Skip to content

Instantly share code, notes, and snippets.

@ojroques
Last active May 14, 2021 17:06
Show Gist options
  • Save ojroques/23adfcb1aa4a5b3878b1fc86c0148309 to your computer and use it in GitHub Desktop.
Save ojroques/23adfcb1aa4a5b3878b1fc86c0148309 to your computer and use it in GitHub Desktop.
docker cheatsheet

DOCKER cheatsheet

A list of commands for Docker.

Contents

General

List all available commands:

docker

View the options available to a specific command:

docker <subcommand> --help

View system-wide information about Docker;

docker info

Clean up any resources that are dangling (not associated with a container) in addition to any stopped containers and all unused images (-a):

docker system prune -a

Image management

Search for an image:

docker search <image>

Download an image:

docker pull <image>

List all downloaded images:

docker images

Remove an image:

docker rmi <image>

Container information

Get detailed information about a container:

docker inspect <container_id>

Provide the statistics of a running container:

docker stats <container_id>

See the top processes within a container:

docker top <container_id>

Container creation

Run an image:

docker run <image>

Run an image (Ubuntu here) in a container named myname with access to an interactive (-i) shell (-t) that removes itself when stopped (--rm):

docker run -it --rm --name myname ubuntu

Run an image and map a local directory to a container directory:

docker run -v source/:dest/ <image>

Container management

View all (-a) containers (active and inactive) with their size (-s):

docker ps -as

Start a stopped container:

docker start <container_id>

Stop a running container:

docker stop <container_id>

Remove a container:

docker rm <container_id>

Attach to a running container:

docker attach <container_id>

Detach from an interactive shell (-it) inside a container:

CTRL-p CTRL-q

Saving containers

Commit changes to a new Docker image:

docker commit -m "Commit message" -a "Author name" container_id repository/new_image_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment