Docker is a fantastic tool, one of favorite in recent years, but it can have some unexpected behavior sometimes.
If you ever mount volumes to your Docker containers to provide access to shared files between your container and host, you might have run into this issue. When you mount a volume into your Docker container, Docker will override any existing files, data, etc. in that directory.
Let’s look at an example:
Dockerfile
...
COPY myapp/ /app
...
Docker Run
docker run -v $(pwd)/myotherapp:/app node
Both our Dockerfile and our Docker run command are both trying to put files into the /app
directory, one of them has to win. Docker will default to the docker run commands parameters, overriding anything defined elsewhere.