Run commands on create a new Docker container
Is it possible to add instructions like
Dockerfile that, instead of run on
docker build command, execute when a new container is created with
docker run? I think this can be useful to initialize a volume attached to host file system.
2 Solutions collect form web for “Run commands on create a new Docker container”
Take a look at the ENTRYPOINT command. This specifies a command to run when the container starts, regardless of what someone provides as a command on the
docker run command line. In fact, it is the job of the
ENTRYPOINT script to interpret any command passed to
I think you are looking for the
The main purpose of a
CMDis to provide defaults for an executing
container. These defaults can include an executable, or they can omit
the executable, in which case you must specify an
instruction as well.
Note: don’t confuse
RUNactually runs a command and
commits the result;
CMDdoes not execute anything at build time, but
specifies the intended command for the image.
You should also look into using Data Containers see this excellent Blog post.
Persistent volumes with Docker – Data-only container pattern