Skip to content

Instantly share code, notes, and snippets.

@thales17
Last active July 26, 2017 14:20
Show Gist options
  • Save thales17/5007d7843a6fc271fed645732dff6209 to your computer and use it in GitHub Desktop.
Save thales17/5007d7843a6fc271fed645732dff6209 to your computer and use it in GitHub Desktop.
Docker Cheat Sheet

Attach to running Container:

docker attach MY_CONTAINER

Detach from Container:

ctrl+pq

List All Containers:

docker ps -q Use -q to only list their IDs

List Containers that use an Image:

docker ps -f="ancestor=MY_IMAGE" -q -a

Stop All Containers:

docker stop $(docker ps -a -q)

Remove All Containers:

docker rm $(docker ps -a -q)

Docker Build (Creates image):

docker build -t MY_IMAGE PATH_TO_FOLDER_WITH_DOCKERFILE Use --no-cache if you want to avoid using cache

Docker Run (Creates container):

docker run --name MY_NAME --network=MY_NETWORK -d SOME_IMAGE

List Images:

docker image ls

Remove All Images:

docker rmi $(docker image ls -q)

List all networks

docker network ls

List Bridge IPs of all running containers

docker network inspect bridge

Create user defined network

docker network create --driver bridge MY_NETWORK

Steps for updating a container image with new code

  • Push up new code
  • Stop all running containers using that image (That you want updated)
  • Delete all containers using that image (That you want updated)
  • Delete the image
  • Rebuild the image
  • Recreate the containers

Resources

Dockerfile reference [Docker run reference] (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