Skip to content

Instantly share code, notes, and snippets.

@joseluisq
Last active February 25, 2020 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save joseluisq/cc732518192687c1689b270749d72e1f to your computer and use it in GitHub Desktop.
Save joseluisq/cc732518192687c1689b270749d72e1f to your computer and use it in GitHub Desktop.
How do you get into a Docker image?

How do you get into a Docker image?

We can do this running our image interactively which creates a temporary container for:

docker run --rm -it \
    --name my_container \
    --volume $PWD:/some_dir_in_container \
    --workdir /some_dir_in_container \
    golang:1.13-buster bash

Description:

  • $PWD above indicates your current working directory. You can change it with a custom path as well.
  • --rm tells Docker to remove the container created after an exit.
  • -it combines --interactive and --tty options in order to keep stdin open even if not attached and allocate a pseudo-TTY.
  • --volume optional volume to bind with container.
  • --workdir optional way to set a working directory inside the container.

Additionally you can append other options like --user in order to switch to a specific user. E.g --user myuser:mygroup

More details about options available refer to https://docs.docker.com/engine/reference/run/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment