Docker Cheatsheet

Posted on  by 



Docker’s purpose is to build and manage compute images and to launch them in a container. So, the most useful commands do and expose this information.

  • Docker Cheat Sheet Process Management # Show all running docker containers docker ps # Show all docker containers docker ps -a # Run a container docker run: # Run a container and connect to it docker run -it: # Run a container in the background docker run -d: # Stop a container docker stop.
  • Docker Cheat Sheet PDF You can find all the listed commands in a convenient one-page reference sheet seen below. To save it for future use, you can also download our Docker Command Cheat Sheet.

Official Docker Cheat Sheet - Don’t use this one a ton, but you might. Has a lot of the basics and is the official docker.com cheat sheet. Red Hat Developers Compresensive Cheat Sheet - A small 6 page pdf that covers container, image, network, registery, and volume related commands. Also has an overview of the Dockerfile syntax. Docker Cheat Sheet Build Build an image from the Dockerfile in the current directory and tag the image docker build -t myimage:1.0. List all images that are locally stored with the Docker Engine docker image ls Delete an image from the local image store docker image rm alpine:3.4 Share Run Run a container from the Alpine version 3.9. Docker is fantastic tool for building out your infrastructure, however it does have a fairly steep learning curve. That’s why I created this Docker Cheat Sheet. I was constantly looking up what docker commands I needed to run to build an image from a dockerfile, run a container, mount a volume, etc.


Here’s a cheat sheet on the top Docker commands to know and use.

(This is part of our Docker Guide. Use the right-hand menu to navigate.)

Images and containers

The docker command line interface follows this pattern:
docker <COMMAND>

The docker images and container commands grant access to the images and containers. From here, you are permitted to do something with them, hence:

There are:

  • is lists the resources.
  • cp copies files/folders between the container and the local file system.
  • create creates new container.
  • diff inspects changes to files or directories in a running container.
  • logs fetches the logs of a container.
  • pause pauses all processes within one or more containers.
  • rename renames a container.
  • run runs a new command in a container.
  • start starts one or more stopped containers.
  • stop stops one or more running containers.
  • stats displays a livestream of containers resource usage statistics.
  • top displays the running processes of a container.

View resources with ls

From the container ls command, the container id can be accessed (first column).

Control timing with start, stop, restart, prune

  • start starts one or more stopped containers.
  • stop stops one or more running containers.
  • restart restarts one or more containers.
  • prune (the best one!) removes all stopped containers.
Docker

Name a container

View vital information: Inspect, stats, top

  • stats displays a live stream of container(s) resource usage statistics
  • top displays the running processes of a container:
  • inspect displays detailed information on one or more containers. With inspect, a JSON is returned detailing the name and states and more of a container.

Additional resources

For more on this topic, there’s always the Docker documentation, the BMC DevOps Blog, and these articles:

Docker is an increasingly popular tool designed to make it easier to create, deploy and run applications within a container. We recently published an article – Data Scientist guide for getting started with Docker – which hopefully laid out some of the basics. As we have done in the past with SQL, Python Regular Expressions and many others, we thought it would be useful to have a centralized cheat sheet for Docker commands, which we’ve based on Docker’s official cheat sheet:

Install

First off, you’ll need to head over to the Docker site to install a version of the software.

To ensure it’s been installed correctly, open the command line and type docker version. This should display something like the below:

Build

docker build [OPTIONS] PATH | URL | -

Common OptionsExplanation
--add-hostAdd custom host-to-IP mapping (host:IP)
--cache-fromImages to consider as cache sources
--compressCompress the build using gzip
--file, -fName and route of Docker file
--force-rmAlways remove intermediate containers
--labelSet the metadata for the image
--memory, -mSet a memory limit
--no-caheDo not use cache
--rmRemove intermediate containers after a successful build
--tag, -tName and optionally tag an image in the ‘name:tag’ format
--targetSet the target build stage

Builds an image from a Dockerfile

docker images

Lists all of the images that are locally stored in the docker engine

docker rmi IMAGE_NAME

Removes one or more images

Ship

docker pull IMAGE_NAME[:TAG]

Pulls an image or a repository from a registry

docker push IMAGE_NAME[:TAG]

Pushes an image or a repository to a registry

docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]

Creates a tag TARGET_IMAGE that refers to SOURCE_IMAGE

docker login [OPTIONS] [SERVER]

Common OptionsExplanation
--password, -pPassword
--username, -uUsername

Docker Cheat Sheet Commands

Logs into a docker registry

docker logout [SERVER]

Logs out of a docker registry

Run

docker create [OPTIONS] IMAGE_NAME

Creates a new container. This is the same as docker run, but the container is never started. See docker run for options

docker run [OPTIONS] IMAGE_NAME

Common OptionsExplanation
--add-hostAdd custom host-to-IP mapping (host:IP)
--attach, -aAttach to STDIN, STDOUT, STDERR
--hostname, -hContainer host name
--interactive, -iKeep STDIN open even if not attached
-itConnect the container to the terminal
--label, -lSet metadata on the container
--memory, -mSet a memory limit
--mountAttach a filesystem mount to the container
--nameAssign a name to the container
--networkConnect a container to a certain network
--publish, -pExpose certain ports to the container
--rmAutomatically remove the container when it exits
--volume, -vBind mount a volume
--workdir, -wSet the working directory inside the container

Run a command in a new container

docker start CONTAINER_NAME

Start one or more containers

Docker

docker stop CONTAINER_NAME

Stop one or more running containers

Docker Cheat Sheet

docker kill CONTAINER_NAME

Kill one or more running containers

docker ps

List all containers

docker rm CONTAINER_NAME

Remove one or more containers

Data Science Examples

FROM ubuntu

Docker

RUN apt-get install python3

This Dockerfile would install python3 on top of Ubuntu layer. Dockerfiles are text files that define the environment inside the container

This Dockerfile would:
- install python3 on top of Ubuntu layer
- create a /home/jupyter directory on the container
- copy in contents from the /src/jupyter folder on the user's machine
- Expose port 8000
- Run Jupyter notebook

docker pull tensorflow/tensorflow

Docker Cheat Sheet 2020

Pull a latest TensorFlow image down

docker run -it -p 8000:8000 tensorflow/tensorflow

Run TensorFlow image in a container on port 8000

Docker Cheat Sheet Pdf 2020

Related:





Coments are closed