I would like to run this command:
docker run docker-mup deploy --config .deploy/mup.js
where docker-mup
is the name the image, and deploy
, --config
, .deploy/mup.js
are arguments
My question: how to mount a volume such that .deploy/mup.js
is understood as the relative path on the host from where the docker run
command is run?
I tried different things with VOLUME
but it seems that VOLUME does the contrary: it exposes a container directory to the host.
I can't use -v because this container will be used as a build step in a CI/CD pipeline and as I understand it, it is just run as is.
If you want to pass multiple build arguments with docker build command you have to pass each argument with separate — build-arg. docker build -t <image-name>:<tag> --build-arg <key1>=<value1> --build-arg <key2>=<value2> .
PWD is an environment variable that your shell will expand to your current working directory. So in this example, it would mount the current working directory, from where you are executing this command, to /usr/src/app inside your container.
How to Mount Local Directories using docker run -v. Using the parameter -v allows you to bind a local directory. -v or --volume allows you to mount local directories and files to your container. For example, you can start a MySQL database and mount the data directory to store the actual data in your mounted directory.
The -v flag mounts the current working directory into the container. The -w lets the command being executed inside the current working directory, by changing into the directory to the value returned by pwd . So this combination executes the command using the container, but inside the current working directory.
I can't use -v because this container will be used as a build step in a CI/CD pipeline and as I understand it, it is just run as is.
Using -v
to expose your current directory is the only way to make that .deploy/mup.js
file inside your container, unless you are baking it into the image itself using a COPY
directive in your Dockerfile
.
Using the -v
option to map a host directory might look something like this:
docker run \ -v $PWD/.deploy:/data/.deploy \ -w /data \ docker-mup deploy --config .deploy/mup.js
This would map (using -v ...
) the $PWD/.deploy
directory onto /data/.deploy
in your container, set the current working directory to /data
(using -w ...
), and then run deploy --config .deploy/mup.js
.
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