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

后端 未结 16 1947
你的背包
你的背包 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:53

    You can use cat if it's installed, which will most likely be the case if it's not a bare/raw container. It works in a pinch, and ok when copy+pasting to a proper editor locally.

    cat > file
    # 1. type in your content
    # 2. leave a newline at end of file
    # 3. ctrl-c / (better: ctrl-d)
    cat file
    

    cat will output each line on receiving a newline. Make sure to add a newline for that last line. ctrl-c sends a SIGINT for cat to exit gracefully. From the comments you see that you can also hit ctrl-d to denote end-of-file ("no more input coming").

    Another option is something like infilter which injects a process into the container namespace with some ptrace magic: https://github.com/yadutaf/infilter

提交回复
热议问题