Docker Run Cheat Sheet

  



Docker exec docker exec options CONTAINER COMMAND -d, -detach # run in background -i, -interactive # stdin -t, -tty # interactive Example $ docker exec appweb1 tail logs/development.log $ docker exec -t -i appweb1 rails c Run commands in a container. Docker-cheat-sheet Docker Commands, Help & Tips. We could do '$ docker container run -publish 8000:80 -detach nginx' to use port 8000. We will discuss commands to create docker image,container,run,start and stop and different aspects. Create an docker image from docker file — docker build -t Imagename. Docker is an open-source platform that can be used to build, ship, and run applications by packaging software in containers. Docker has a lot of commands and options, and it is very difficult to remember every command. This article provides a cheat sheet of the most commonly used Docker commands.

docker daemon

Enable buildkit

Add to /etc/docker/daemon.json:

docker-compose

Docker Run Command Cheat Sheet. Docker container run -name web -p 5000:80 alpine:3.9: Run a container from the Alpine version 3.9 image, name the running container “web” and expose port 5000 externally, mapped to port 80 inside the container. Docker container stop web.

Devices

Labels

External Network

Dockerfile

Docker Stop Signal

imagemagick

vim

path update

download & extract tar.gz

gpg dirmgr explained

purge

list what exposed ports do

cassandra

gosu

debian

copy with proper permissions

su-exec

setgid

npm

gosu

tini

node

redis

docker

google cloud sdk

kubectl

pip

locale

tomcat

https://github.com/Unidata/tomcat-docker/blob/master/Dockerfile

gosu tomcat

Secure repository setup

create application folder structure

Download and clean up in one layer

Package Manager tricks

Metadata

Make sure to add ARG statements as late as possible to not invalidate the layer cache needlessly.Each ARG will be prepended to all subsequent RUN statements, i.e. building an image with the following Dockerfile docker --pull --tag foo:latest --build-arg GIT_COMMIT=46e24af6 --build-arg USERNAME=flask .

Effectively results in the following calls:

Since the git commit hash will typically change with each build the build will not make good use of Docker’s layer cache

Python

Golang

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:

Docker

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]

Docker Run Cheat Sheet Excel

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

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 stop CONTAINER_NAME

Stop one or more running containers

docker kill CONTAINER_NAME

Docker Cheat Sheet 2020

Kill one or more running containers

Docker Build Cheat Sheet

docker ps

List all containers

docker rm CONTAINER_NAME

Remove one or more containers

Data Science Examples

FROM ubuntu

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

Pull a latest TensorFlow image down

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

Run TensorFlow image in a container on port 8000

Related: