Skip to content

Instantly share code, notes, and snippets.

@djburdick
Last active May 28, 2019 18:21
Show Gist options
  • Save djburdick/7459d539b25f505909296c06a2128dec to your computer and use it in GitHub Desktop.
Save djburdick/7459d539b25f505909296c06a2128dec to your computer and use it in GitHub Desktop.
Docker cheatsheet
Commands:
docker run hello-world # run container
docker run -d -p 4000:80 hello-world # run in the background on port 4000
docker container stop CONTAINER_ID # stop container id
docker stop $(docker ps -a -q) # stop all containers
docker image ls # list images
docker container ls --all # list all containers
docker build -t appname . # build the app in currect dir
# Services
docker stack deploy -c docker-compose.yml getstartedlab # start a service
docker service ls # list services
docker service ps getstartedlab_web # show all the tasks for a service
docker stack rm getstartedlab # take down the service
# Volumes
# To mount a local directory (changes are dynamically synced) in docker-compose.yml do:
volumes:
- ./dir_to_mount:/app/dir_to_mount
Files:
"docker-compose.yml" - defines how Docker containers should behave in production
"requirements.txt" - a file to specify dependencies to install. This needs to be run from the Dockerfile with something like: "RUN pip-3.3 install -r requirements.txt"
"Dockerfile" - the main file the defines the commands to build a Docker image
Terms:
"image" - an application and related software. Images are built from a series of "layers" (commands executed to build the image). Because they can become quite large, images are designed to be composed of layers of other images. the image is the recipe, the container is the cake. you can make as many cakes as you like with a given recipe
"container" - an instance of an image. can have many running containers of the same image
"Dockerfile" - definies what happens inside the environment in your container. Exposes ports, sets up images etc...
"repository" - collection of images
"registry" - collections of repositories
"compose" - uses a yaml file to define and run multi-container docker applications
"service" - a piece of an application responsible for one thing. eg: at YouTube the upload functionality could be a service, the transcoding another service etc... In docker a service runs just one image, but it says how many instances to run and what ports of that image etc... It's a way of defining all the containers that are running for that image
"task" - a single container running in a service
@djburdick
Copy link
Author

docker exec -it infinity_postgres_1 psql -U postgres

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