Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker how to pass a relative path as an argument

Tags:

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.

like image 828
znat Avatar asked Jul 12 '18 18:07

znat


People also ask

How do you pass arg Docker?

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> .

What is $( PWD in Docker?

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 do I mount a local directory into a 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.

What does v flag do in Docker?

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.


1 Answers

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.

like image 129
larsks Avatar answered Sep 20 '22 21:09

larsks