Editing Files inside of a Docker Container

后端 未结 2 1111
有刺的猬
有刺的猬 2021-02-07 20:55

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

2条回答
  •  春和景丽
    2021-02-07 21:41

    There are multiple ways to achieve that:

    You can enter the container by running the command:

    docker exec -it  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 :/path/to/file/in/container .
    

    Edit the file and then copy it back into the container:

    docker cp  :/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.

提交回复
热议问题