CMD line is ignored

Hi everyone,

I am totally new to Docker.

My Dockerfile has this :

FROM python:3
WORKDIR /usr/src/app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["python, “”]

The last line is ignored.

Here’s how I try to run it :

sudo docker-compose build

This is run on a VirtualBox Ubuntu 22.04 VM on my Windows 11 PC.



This can’t be the exact Dockerfile you used, as the CMD line has a syntax error.

The base image python:3 doesn’t use ENTRYPOINT, as such the CMD instruction should be executed, unless the service in your compose file that based on your image declares entrypoint: or command:, as both would override the CMD instruction from the Dockerfile.

Furthermore, please format your text by using a “</> Preformated Text” block.

Thanks for taking the time to respond.

I corrected the CMD line :

  *CMD ["python", ""]*

And I noticed I had forgotten to put the info in the requirements.txt file :


But even after changes, the 6th line, i.e. the CMD, is still ignored.

Btw, I am sorry, I don’t understand which part of the text should be preformatted.

Nice response from simple Google search:

Because CMD and ENTRYPOINT work in tandem, they can often be confusing to understand. However, they have different effects and exist to increase your image’s flexibility: ENTRYPOINT sets the process to run, while CMD supplies default arguments to that process

Only true if both are used. Without an ENTRYPOINT instruction (either inherited by the base image or declared in the Dockerfile), the CMD instruction specifies the default process to run and it’s arguments.

There is a statement in your post and the title “CMD line is ignored”, which simply never happens, and there is no explanation why you think it is ignored. So there is nothing to answer here. That’s why I didn’t write before and followed the discussion to see where it goes.

So why do you think it? Despite the replies mentioning entrypoint and cmd you haven’t addressed what you didn’t understand or why you thought it was irrelevant. It is extremely important to understand the keywords in an answer and if you don’t, even after reading the linked documentations, ask for more explanation pointing out what you didn’t understand.

You run docker-compose build. Now why do you think the CMD line should have any affect during building the image? What was that you expected to see and you didn’t see.

These things in a technical question are always important regardless of what the topic is, not just in case of Docker. Otherwise you can say the line is ignored, and we can say it isn’t. And that’s the end of the discussion.

Please, read this guide: How to format your forum posts

Now if you want to learn about the entrypoint and cmd and when these are running, you can read my blogpost. There is also a video in the post embedded from youtube:

I write and talk about all the instructions related to command executions. In your case, I think CMD is irrelevant, as you don’t run a container, just build the image.