Philip Kirkbride
Philip Kirkbride

Reputation: 22889

Docker CMD when base image has a CMD?

I have a Dockerfile which starts with:

FROM puppet/puppetserver

When I look at the source container it is built from another:

FROM puppet/puppetserver-standalone:5.0.0

The second contains a CMD command:

ENTRYPOINT ["dumb-init", "/docker-entrypoint.sh"]
CMD ["foreground" ]

In my own container I end with:

COPY start.sh /
CMD /start.sh

The CMD run but with unexpected results:

puppetserver: '/bin/sh' is not a puppetserver command. See 'puppetserver --help'.

I know that I have bash availible because I'm using RUN commands.sh before CMD in the same Dockerfile.

How do CMD commands stack when inheriting from base images?

Is my CMD not run as a normal bash command and instead run in conjunction with the CMD of the base image?

Upvotes: 4

Views: 2796

Answers (2)

tlo
tlo

Reputation: 1631

See https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact

CMD should be used as a way of defining default arguments for an ENTRYPOINT command or for executing an ad-hoc command in a container.

and https://docs.docker.com/engine/reference/builder/#cmd

There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect.

Upvotes: 2

Tarun Lalwani
Tarun Lalwani

Reputation: 146630

You need to reset the ENTRYPOINT from the parent image

COPY start.sh /
ENTRYPOINT []
CMD /start.sh

Upvotes: 4

Related Questions