I have several base docker images which are not owned by me (so I cannot modify them). However, I'm creating new images from them with additional things installed.
What I can't figure out is how to tell dockerfile to copy the CMD (or ENTRYPOINT) of the base image. Something like this:
FROM other:latest RUN my-extra-install CMD <use-the-CMD-from-base-image>
I don't think there's any direct syntax for the CMD command to do what I want. I'm wondering if there's a workaround.
Introduction. There are CMD and ENTRYPOINT as setting items of Dockerfile, but these differences are often confusing for those new to Docker. This is because both of these items can execute the command you want to run on the container when the container is executed.
Both ENTRYPOINT and CMD allow you to specify the startup command for an image, but there are subtle differences between them. There are many times where you'll want to choose one or the other, but they can also be used together. We'll explore all these scenarios in the sections below.
The ENTRYPOINT instruction looks almost similar to the CMD instruction. However, the main highlighting difference between them is that it will not ignore any of the parameters that you have specified in the Docker run command (CLI parameters).
ENTRYPOINT is the other instruction used to configure how the container will run. Just like with CMD, you need to specify a command and parameters. However, in the case of ENTRYPOINT we cannot override the ENTRYPOINT instruction by adding command-line parameters to the `docker run` command.
If you left it blank in your new Dockerfile, it will inherit the one from the base image.
For example:
base
FROM ubuntu CMD ["echo", "AAA"]
layer1
FROM base
If you build above images and run layer1
you will get the following:
$ sudo docker run -it layer1 AAA
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With