Skip to content

Instantly share code, notes, and snippets.

@johnbuhay
Last active October 25, 2018 19:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnbuhay/93f465315f7ea1d2a3963c356101e19b to your computer and use it in GitHub Desktop.
Save johnbuhay/93f465315f7ea1d2a3963c356101e19b to your computer and use it in GitHub Desktop.
Resources for Getting Started with Docker
This file is used to name this gist.
@mattjstar
Copy link

Docker Cheat Sheet

docker ps - what docker images are running

docker ps -a - all images, even ones that were scheduled and died

docker images - lists images available locally

  • A tag points to a SHA, which could mean different things. We have multiple tags on the same image. If you want to have multiple versions of your app with the same image (so you don't have to waste multiple images)
  • Floating tags is nice for building locally

docker build -t me/locations-api . - builds your image based on your current directory's dockerfile called "me/locations-api"

docker run - runs a prebuilt docker image

  • Example way to run something locally: docker run -p 1492:3000 --env-file .env -d me/locations-api
  • -d is daemon mode, so it doesn't lock up your terminal. If it's in daemon mode, you have to explicitly docker stop it
  • This runs one process until that process is complete

docker exec -i -t me/locations-api bash

  • bash into my local running container after running the above command

docker logs -f #{CONTAINER_ID} - tailing logs to stderr or stdout (follow)

docker stop #{CONTAINER_ID} - stop running docker container

Building Dockerfile

Docker tries to cache all commands in the Dockerfile. Every command becaomes a Docker layer. It's also read in order. Typically you want to have things that change often at the bottom, and things that change often on top, to prevent from rebuilding unnecesarry layers all the time.

FROM - You can have Dockerfiles inherit from the same base layer

RUN - typically busts cache. All these commands happen in one layer

ADD - unpacking a tar that is local, or adding a url that's available publically

COPY - more ideal than add if you're just trying to copy files over

John's gist

Get started with Docker for Mac: https://docs.docker.com/docker-for-mac/
Docker Orientation: https://docs.docker.com/get-started/
Docker CLI Reference: https://docs.docker.com/engine/reference/commandline/cli/
Best practices for writing Dockerfiles: https://docs.docker.com/engine/userguide/eng-image/dockerfile_best-practices/

Docker Tutorials: https://github.com/docker/labs/
Docker Engine user guide: https://docs.docker.com/engine/userguide/
Glossary: https://docs.docker.com/glossary/

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