Docker Community Forums

Share and learn in the Docker community.

Dockerfile confusion! Running CMD before setting up base image?

build

(Lgeeh) #1

I have created a very basic dockerfile,

FROM pypi/dnslib
ADD dns.py /
CMD [“python”, “dns.py”]

After building the image and trying to run it, my application throws an error that there is no dnslib module.
I don’t see the image trying to install/build the pypi/dnslib.

Without my CMD , the first thing I see is it collecting/installing dnslib via pip. I drop into shell, I am able to start my application.

Can anyone explain what is happening??


(Sam) #2

what do you mean ‘without my CMD’? the first thing I see

if you docker inspect the pypi/dnslib

what is its entrypoint and cmd list?


(Lgeeh) #3

I wasn’t able to post my full comment as it was detecting links in the post…

When I remove the line CMD [“python”, “dns.py”] and build the docker image, then run it,the output from docker shows it is collecting and installing pip.
I have tried using an entrypoint to run my application however have the same issue.

This is the dockerfile for pypi/dnslib
FROM python
CMD [ “pip”, “install”, “dnslib==0.9.6” ]


(Sam) #4

based on my reading of the doc, if YOU add a CMD= then any previously specified CMD= is NOT RUN.

looking at one of my containers, built on top of ubuntu, the previous CMD= is not even listed. only mine.

SO, it looks like YOU have to inspect the prior image and add that on to YOUR dockerfile to make it work.


(Lgeeh) #5

I would have expected it to build the base image first and then my dockerfile. If the previous image is using CMD how would I go about changing that?


(Sam) #6

If u are in charge of the source image, then you might change the cmd to a run and have it do the install at build time instead of run time.
Then others can extend the base easily

If u are not in charge, then you will have to discover and include the base image cmd with yours, of course executing theirs before yours