How can I edit the config files that are inside of a docker container that has been downloaded on the host?
I am using this tutorial but I am not sure where to find and edit the traefik.toml file
How can I edit the config files that are inside of a docker container that has been downloaded on the host?
I am using this tutorial but I am not sure where to find and edit the traefik.toml file
There are multiple ways to achieve that:
You can enter the container by running the command:
docker exec -it <container-name> bash
Note however depending on the container you may not have a simple text editor..
Another alternative would be to copy the file you want to edit from the container onto your host by running:
docker cp <container-name>:/path/to/file/in/container .
Edit the file and then copy it back into the container:
docker cp <file> <container-name>:/path/to/file/in/container
There's also a bind mount which will mount a host folder into the container
docker run -v $(pwd)/files:/dir/containing/file/in/container ...
Files created in that folder in the container after the mount will be visible on the host BUT if that folder already existed in the container before the mount, it will be shadowed by the host folder making it inaccessible to either host or container.
I was running into the same issue and found a nice way to handle this. Using VS Code and the docker extension, get the container running. In the list of Containers, right click on the one you want to edit. Choose: Attach Visual Studio Code.
Another VS Code instance should open up that is directly attached to the container. Click on the Open Folder and navigate to the file you wish to edit. Pour a nice stout, chill for a moment, then get back to coding. :)
Yes, works perfect with Windows containers too.
Run a cmd into a crashing container to prevent exit:
docker run -dit docker/image cmd
Start VS Code with the docker extension. There is a open and download option for each file, very nice.
You can expose the container over port 22 and then edit whatever file you want over ssh.
vim scp://user@myserver[:port]//path/to/file.txt
See more: How to edit file within Docker container or edit a file after I shell into a Docker container?
If you want to add a line to a file such as a line of config you can use echo like this and append it to a file:
echo 'super-setting: "10.96.85.221:9200"' >> config.yml
This only works if you want to add extra lines and not if you want to edit an existing line.
I've found it a quick and easy way to make and test temp changes to a file in a docker container.