Docker Cheat Sheet

01 September 2018 devopsTechnology
Share with:

Since I’ll start to work with docker – I’ll need a point of reference. I’ll continue to update this “article” as I continue to work with docker.

Update 2022 – I haven’t used docker for nearly three years – if you land here – take everything with a grain of salt!


Create Basics Images Network Volumes


Creating a container

docker container run
\ -p <src>:<dst> // <src> – port on host machine
// <dst> – port on container
\ –network <name> // put the container in network <name>
\ –name <name> // name of the container
\ –detach // keep it running in the background
\ -v <name>:</path> // <name> of the volume
// <path> where the volume is mounted
<host_path>:<container_path> // mounts a path on host to a container
\ -e <variable> // set environment variables

containers basics

docker container run -p 80:80 <image_name> --network <network_name> --name --detach <container_name>

//creates a container from image ‘image_name’ with name ‘container_name’ and lets it work in background (detach)

docker container ls -a 

//list all containers

docker container run -it <image> <command>

// start container instance with the command started bash

docker container exec -it <container_name> <command>

// run command on container_name

docker container logs -f <container_name>

// monitor the logs of the container in real time

Images

docker image tag <source image_name> <target image_name>

// creates a new tag from source image

docker image build -t <tag_name> .

//creates an image from current directory’s DockerFile

Network

docker network ls

// list networks

docker network inspect <network>

//prints configuration of networks

docker network create <name>

//creates a basic network

docker network connect <network> <container>

//adds container to a network

docker network disconnect <network> <container>

//disconnects container from a network

Volumes

docker volume ls

//lists volumes

docker volume inspect <id>

//inspect the volume

txt file
bretfisher samples


Create Basics Images Network Volumes