I am writing a dockerfile that runs a pp that wil use the same argument most of the time.
ENTRYPOINY [ "mayapp" ]
CMD [ "defaultarg" ]
But every now and the it needs to take another argument, since the users will be mostly windows I want to do this without many scripts or extra arguments
docker run my/app somearg
Issue is they need to use a bind volume. However when I add a -v switch it will take that to override the CMD.
docker run my/app -v datadir:/app/datadir
This will replace 'defaultarg' with '-v' Is there a way to stop this from happening without moving the CMD arg to a env/ARG?
I have used the build args switch because I couldn't find any info. However resolving this without build-args would be nicer since it less switches on running the container.
CodePudding user response:
Parameters on docker run
come in 2 flavours. Parameters for docker are placed before the image name and parameters for the container are placed after the image name. As you've discovered, parameters for the container replace any CMD statement in the image.
The -v
parameter is for docker, so it should go before the image name, like this
docker run -v datadir:/app/datadir my/app
That will leave your CMD intact, so it'll work as before.