Given the following file structure:
configs ├── config.docker.js ├── config.js ... ├── OTHER CONFIG FILES
The purpose is that we want to use
config.js in the built docker image and mount
configs directory in the container while it’s running, so we can get the best of Docker.
However, it won’t work in the normal configurations in Dockerfile and the docker run command line:
... COPY ./configs /app/configs RUN mv /app/configs/config.docker.js /app/configs/config.js ...
docker run -v ./configs:/app/configs -v ./configs/config.docker.js:/app/configs/config.js THE_BUILT_IMAGE
It won’t work, in the container, we can see the second override
volume mount option takes no effect. The
config.js mapped independently in the container.
To solve this problem, we can introduce
.dockerignore file to ignore the
config.js file in the building and mounting process:
In .dockerignore file
After get the
.dockerignore file ready, rebuild the image and run the same
docker run command line. In the running container, we got:
-rw-r--r-- 1 root root 218 May 28 16:54 config.docker.js -rw-r--r-- 1 root root 218 May 28 16:54 config.js
Both of them mapped to the same ./configs/config.docker.js file. And changes to this file locally will immediately reflect in the running container.