Skip to content

Instantly share code, notes, and snippets.

@G-Goldstein
Last active February 8, 2019 16:48
Show Gist options
  • Save G-Goldstein/2551a606624ef4680eb4d51dc7e14bdc to your computer and use it in GitHub Desktop.
Save G-Goldstein/2551a606624ef4680eb4d51dc7e14bdc to your computer and use it in GitHub Desktop.
Docker Dojo 1 Cheat Sheet

Terminology

A Docker image is a template for an application, together with its dependencies, runtime environment and metadata.

A Docker container is a running instance of a Docker image.

Commands

Use command docker alone to see Docker usage. You may need root access.

For a Docker command, use --help to display detailed usage information:

docker run --help

Follow run by an image name to download that image (if it's not already present) and run a container from it:

Containers may be terminating, and so have a finite lifespan:

docker run hello-world

or containers may try to run forever:

docker run training/webapp

Use Ctrl+C to end a terminal session linked to a container.

Use ps to see all active containers on the system:

docker ps

Use stop to stop the running of an active container. Refer to it by either name or ID:

docker stop 8c2c34626f7b

On a run command, use the -d argument to run detached:

docker run -d training/webapp

On a run command, use the -p argument to publish the container's ports to the host machine:

-p lets you specify your own port mappings, with an argument. The below maps host port 9000 to container port 5000:

docker run -d -p 9000:5000 training/webapp

Multiple -p arguments can be passed, each with their own argument:

docker run -d -p 5000:5000 -p 6000:6000 training/webapp

-P uses image metadata to provide suitable mappings:

docker run -d -P training/webapp

Explore an image by starting a shell in an interactive (-i) terminal (-t) session:

docker run -it training/webapp /bin/bash

Leave with exit

Set environment variables on run with -e:

docker run -Pd -e PROVIDER=User training/webapp

The -e argument can be specified multiple times, each for a different environment variable.

Mount host volumes on run with -v:

docker run -v C:\Users\goldsteing\dockertest:/usr/share/nginx/html -Pd nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment