Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating multiple directories using docker RUN

Tags:

docker

When running the following in a terminal on my Linux machine:

mkdir -p /tmp/storage/{logs,framework,app}

It create the following directories:

/tmp/storage/app
/tmp/storage/framework
/tmp/storage/logs

While building using RUN in a Dockerfile results in a single directory called:

/tmp/storage/{logs,framework,app}

I know I could just create multiple RUN each with a mkdir pr directory but I'm curious to why the other command doesn't work and if there is a way of actually doing it?

like image 559
Jacob Avatar asked May 20 '15 20:05

Jacob


People also ask

How do I map a directory in Docker?

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.

Does Docker Workdir create directory?

It also sets the working directory of a Docker container, which means if we have specified any path using WORKDIR and when we connect the container using the 'exec' command, then it will directory land us to that directory. Docker daemon creates the folder if the specified directory does not exist.

Can Docker container run multiple services?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

Can we have multiple Workdir in Dockerfile?

you can have multiple WORKDIR in same Dockerfile. If a relative path is provided, it will be relative to the previous WORKDIR instruction. If no WORKDIR is specified in the Dockerfile then the default path is / . The WORKDIR instruction can resolve environment variables previously set in Dockerfile using ENV.


1 Answers

RUN commands use /bin/sh, while you are most likely using /bin/bash at the terminal. To get the Bash behavior, use Bash:

RUN bash -c 'mkdir -p /tmp/storage/{logs,framework,app}'
like image 189
jwodder Avatar answered Oct 25 '22 09:10

jwodder