Skip to content

Instantly share code, notes, and snippets.

@ktilcu
Created July 6, 2018 19:54
Show Gist options
  • Select an option

  • Save ktilcu/f6d0856e319d6768b9c6c06950a20ca1 to your computer and use it in GitHub Desktop.

Select an option

Save ktilcu/f6d0856e319d6768b9c6c06950a20ca1 to your computer and use it in GitHub Desktop.
Oft used docker cmds

Docker Basics

  • docker ps Shows you running containers (note the last column name)
  • docker logs <name> Shows you logs from the running container
  • docker logs -f <name> Tails logs from a running container
  • docker build -t <image_tag_name> . Builds the current dir as a docker image
  • docker run <image> creates a container running the specified image
    • --rm remove the container when it exits (good for dev)
    • -e use to set environment variables in the conatiner - one assignment per flag
    • --name set a name for the running container
    • -p forward a host ports traffic to the container port <host>:<container>, e.g., 5000:5000
  • docker run -it <image> <command> start a container running the specified image and then interactively run the command inside the container.
    • used for debugging
    • docker run -it <image> /bin/bash for a shell on a non running container. i.e., it won't run the CMD specified in the Dockerfile
  • docker exec <container> <command> run a command in a running container
  • docker stop -t1 <container> Stop a running container
  • docker restart <container restarts the container with the previous arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment