How to edit Docker container files from the host?

前端 未结 9 2341
孤城傲影
孤城傲影 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:20

    Here's the script I use:

    #!/bin/bash
    IFS=$'\n\t'
    set -euox pipefail
    
    
    CNAME="$1"
    FILE_PATH="$2"
    
    TMPFILE="$(mktemp)"
    docker exec "$CNAME" cat "$FILE_PATH" > "$TMPFILE"
    $EDITOR "$TMPFILE"
    cat "$TMPFILE" | docker exec -i "$CNAME" sh -c 'cat > '"$FILE_PATH"
    rm "$TMPFILE"
    

    and the gist for when I fix it but forget to update this answer: https://gist.github.com/dmohs/b50ea4302b62ebfc4f308a20d3de4213

提交回复
热议问题