I have created an docker image of a website from a build. This image is a website with a nodejs webapp and a .net core website. Both have configs (config.json and web.config respectively).
I have packaged up the image to include other environment configs so I can use an image for a particular environment (QA, Stage, Production, etc) but with a rename of web.config.ENVIRONMENT to web.config and Config.JSON.ENVIRONMENT to Config.JSON.
How can I rename a file on a docker image or rename both of these files? A rename works or a copy config.json.QA to config.json works as well.
Do I need to mount the image, make the config file changes, then start the image in a container?
AFAIK the best and most standard way to modify a Docker image is to use a Dockerfile and “docker build”.
Can’t you write “RUN mv …” line in a Dockerfile, or don’t you have a mv command in the image?
Why not, containerised applications are meant to be immutable not patched in-situ, that’s an anti-patten. If you have different config per environment, mount the appropriate config using a volume.
can you give me a example of running the image while mounting the file?
I have a image/ container that has a site running in the /app folder
so there is an /app/web.config
I want to use that same image but place web.config.qa as web.config
this would allow me to reuse the same image for different environments with just this file changing.
docker run -v /local/web.config.qa:/app/web.config -it -p 8080:8080 myimage
If the file web.config.qa is located in /local on your host and the target file inside the container should be located in /app/web.config, then -v /local/web.config.qa:/app/web.config is correct.
Does it leave a security hole where somebody could change /local/web.config.qa or even delete it and it has an impact on the container that has a volume bind there?
I wonder if this is a new feature for docker for windows. I am using and older version 2.0.0.3
I tried this as well.
docker run -d -p 9090:80 --name QAAAuthService -v e:\configs\appsettings.QAA.json:c:/app/appsettings.json qaaauthservice
docker: Error response from daemon: invalid volume specification: ‘e:\configs\appsettings.QAA.json:c:/app/appsettings.json’: invalid mount config for type “bind”: source path must be a directory.
Can you only mount directories with Docker Desktop for Windows?
Ok it looks like a file to file mapping is not supported in Docker Desktop for windows the docker forums on github. The folder to folder volume mapping is supported.
so this is supported where c:\configs is a folder on the windows host and /app/config is a folder on the container image
docker run -v c:/configs:c:/app/config -d -p 9090:80 qaaauthservice
this is NOT supported on windows docker
docker run -v c:/configs/appsettings.QAA.json:c:/app/config/appsettings.json -d -p 9090:80 qaaauthservice