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?
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.
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.
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.
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.
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}'
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