How do I edit a file after I shell to a Docker container?

后端 未结 16 1891
你的背包
你的背包 2020-11-29 14:22

I successfully shelled to a Docker container using:

docker exec -i -t 69f1711a205e bash

Now I need to edit file and I don\'t have any edito

16条回答
  •  北海茫月
    2020-11-29 14:44

    You can also use a special container which will contain only the command you need: Vim. I chose python-vim. It assumes that the data you want to edit are in a data container built with the following Dockerfile:

    FROM debian:jessie
    ENV MY_USER_PASS my_user_pass
    RUN groupadd --gid 1001 my_user
    RUN useradd -ms /bin/bash --home /home/my_user \
                -p $(echo "print crypt("${MY_USER_PASS:-password}", "salt")" | perl) \
                --uid 1001 --gid 1001 my_user
    ADD src /home/my_user/src
    RUN chown -R my_user:my_user /home/my_user/src
    RUN chmod u+x /home/my_user/src
    CMD ["true"]
    

    You will be able to edit your data by mounting a Docker volume (src_volume) which will be shared by your data container (src_data) and the python-vim container.

    docker volume create --name src_volume
    docker build -t src_data .
    docker run -d -v src_volume:/home/my_user/src --name src_data_1 src_data
    docker run --rm -it -v src_volume:/src fedeg/python-vim:latest
    

    That way, you do not change your containers. You just use a special container for this work.

提交回复
热议问题