M.K. aka Grisu
M.K. aka Grisu

Reputation: 2398

Dockerfile: Specify startup command indepentent from docker run command

I currently got stuck with writing a Dockerfile as base for a bunch of CI test. Our test are run inside a privileged docker container and thus executed by

docker run --privileged -v ${HOME}/project_source/:/project_source -it ciimage:ubuntu bash /project_source/somecommand.sh

Now, for a new set of tests we need to mount nfs inside the docker container, which works due to the privileged container. For simplicity and to avoid that my users try to script around with the nfs stuff, I want to include the nfs mount in the Dockerfile. I created a MWE: Dockerfile:

FROM  ubuntu:focal 
RUN apt update && apt install --yes nfs-common 
COPY start.sh /bin/start.sh
ENTRYPOINT ["/bin/bash", "/bin/start.sh"] 

and start.sh

#!/bin/bash
mkdir -p /run/sendsigs.omit.d
/etc/init.d/rpcbind start
/etc/init.d/nfs-common start
mount nfs-master:/srv/install /mnt 

But after building the Dockerfile, adding a command to the docker run command destroys the startup. Who can I change this in a way that the start.sh is executed independent of the command given by docker run.

Upvotes: 0

Views: 219

Answers (1)

David Maze
David Maze

Reputation: 159495

You should end the entrypoint script with the line

exec "$@"

The docker run command overrides the Dockerfile CMD, which is passed as arguments to the entrypoint. This line replaces the current script with whatever was passed to it as arguments.

(If you need a privileged container, and to run system-level daemons in it, a virtual machine might be a better match; this approach isn't gaining you much isolation over running these processes directly on the host.)

Upvotes: 1

Related Questions