Skip to content

Instantly share code, notes, and snippets.

@vkroz
Last active September 30, 2019 20:42
Show Gist options
  • Save vkroz/eb82b7cc90a955d923e3538c0e9fd605 to your computer and use it in GitHub Desktop.
Save vkroz/eb82b7cc90a955d923e3538c0e9fd605 to your computer and use it in GitHub Desktop.
Docker cheatsheet

Docker playground: https://labs.play-with-docker.com/

Build image

tag coud be enything, it should help to identify application and its version, e.g.

# Build image, can use multiple tags
docker build . -t ${tag1} -t ${tag2} ${buildArgs}

# Push to repo
docker push gcr.io/my-proj/my-app:latest gcr.io/my-proj/my-app:1.0.5

Operating containers

  • List all running images: docker ps
  • Run container
docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.6.0

to run in background, detached -- use -d option, e.g.

docker run -d -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:6.6.0
  • SSH into a running container
docker ps
docker exec -it {{container id}} /bin/bash 
  • Run bash on image
docker images
docker run -it --entrypoint /bin/bash {{image id}}
  • Get logs from running container
sudo docker logs 4bedab917a00

follow log changes

sudo docker logs -f 4bedab917a00

GCR

# List apps
gcloud container images list --repository gcr.io/my-proj

# List app versions
gcloud container images list-tags gcr.io/my-proj/my-app

Frequent troubles

  1. Problem: Docker is running, but gives Cannot connect to the Docker daemon on any command, e.g.
$ docker ps
Cannot connect to the Docker daemon. Is the docker daemon running on this host?

Solution: try to run same command with sudo, e.g. sudo docker os

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