How to edit Docker container files from the host?

前端 未结 9 2220
孤城傲影
孤城傲影 2020-12-13 08:51

Now that I found a way to expose host files to the container (-v option) I would like to do kind of the opposite:

How can I edit files from a running container with

相关标签:
9条回答
  • 2020-12-13 09:24

    I use sftp plugin from my IDE.

    1. Install ssh server for your container and allow root access.
    2. Run your docker container with -p localport:22
    3. Install from your IDE a sftp plugin

    Example using sublime sftp plugin: https://www.youtube.com/watch?v=HMfjt_YMru0

    0 讨论(0)
  • 2020-12-13 09:25

    If you think your volume is a "network drive", it will be easier. To edit the file located in this drive, you just need to turn on another machine and connect to this network drive, then edit the file like normal.

    How to do that purely with docker (without FTP/SSH ...)?

    1. Run a container that has an editor (VI, Emacs). Search Docker hub for "alpine vim"

    Example:

    docker run -d --name shared_vim_editor \
     -v <your_volume>:/home/developer/workspace \
    jare/vim-bundle:latest
    
    1. Run the interactive command:

    docker exec -it -u root shared_vim_editor /bin/bash

    Hope this helps.

    0 讨论(0)
  • 2020-12-13 09:25

    The way I am doing is using Emacs with docker package installed. I would recommend Spacemacs version of Emacs. I would follow the following steps:

    1) Install Emacs (Instruction) and install Spacemacs (Instruction)

    2) Add docker in your .spacemacs file

    3) Start Emacs

    4) Find file (SPC+f+f) and type /docker:<container-id>:/<path of dir/file in the container>

    5) Now your emacs will use the container environment to edit the files

    0 讨论(0)
提交回复
热议问题