Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Editing Files inside of a Docker Container

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

like image 655
Lolling Banana Avatar asked Nov 25 '17 20:11

Lolling Banana


People also ask

Can I edit code in docker container?

The Remote – Containers extension for Visual Studio Code lets you edit files and folders inside Docker containers. It works seamlessly with the VS Code editor features, including IntelliSense, directory indexing, debugging, and extensions.

Can you work inside a docker container?

Once you have your Docker container up and running, you can work with the environment of the Docker container in the same way you would do with an Ubuntu machine. You can access the bash or shell of the container and execute commands inside it and play around with the file system.


1 Answers

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

Third option is to create a bind mount which will effectively expose the file from the container onto the host

docker run -v $(pwd)/files:/dir/containing/file/in/container ...

This will expose the container folder in the "files" directory, and you can edit the file in the host and it will be directly reflected inside the container.

like image 58
yamenk Avatar answered Oct 14 '22 16:10

yamenk