Skip to content

Instantly share code, notes, and snippets.

@ojacques
Created January 11, 2023 16:37
Show Gist options
  • Save ojacques/531a438ea82c8f3b845d3da4c5bab622 to your computer and use it in GitHub Desktop.
Save ojacques/531a438ea82c8f3b845d3da4c5bab622 to your computer and use it in GitHub Desktop.
Edit a file in Docker container when no editor / vi

Context

I need to edit a file in a Docker container. This container does not have vi or an actual editor. I cannot install anything. I don't have access to run chown either.

Solution

  • Login on the Docker host
  • Get the file from the container: docker cp b28b1d60e423:/the/file/that.I.want.json .
  • Get into the container and find out what is the UID/GID which you want to create the file with (use id)
  • Edit the file on the Docker host
  • Copy the file back to the container: tar -cf - that.I.want.json --mode u=+r,g=+r,o=+r --owner 1030 --group 1030 | docker cp - b28b1d60e423:/tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment