Be ready always
Docker Cheatsheet is here to help you with solving from basic to advanced common docker problems. It's a recipe for making docker usage as enjoyable as possible in your daily life.
Connect with me in linkedin or say hi to Twitter.
iname
meansimage name with tag
cname
meanscontainer name
vname
meansvolume name
nname
meansnetwork name
cid
meanscontainer id
cport
meansport in container
hport
meansport in host
cdir
meansdirectory in container
hdir
meansdirectory in host
/p/t/
means/path/to/
$ docker image pull <iname> # pulls image from registry
$ docker image ls # lists images
$ docker image build -t <iname> . # builds image from Dockerfile in current dir
$ docker image build -t <iname> -f </p/t/dockerfile> # builds image from dockerfile with given path
$ docker image rm <iname> # removes image
Running Container
$ docker container run <iname> # runs container with an arbitrary name
$ docker container run --name <cname> <iname> # runs container with a preferred name
$ docker container run -it <iname> <cmd> # runs container in interactive mode with given cmd
$ docker container run -d <iname> # runs container in detached mode
$ docker container run -dit <iname> # runs container in detached interactive mode
Lisiting Containers
$ docker container ls # lists running containers
$ docker container ps -a # lists all(both running and stopped) containers
Start, Stop, Attach and Removing Container
$ docker container stop <cid> # stops a container with given container id
$ docker container stop <cname> # stops a container with given container name
$ docker container start <cid> # restarts a stopped container
$ docker container start <cname> # restarts a stopped container
$ docker container attach <cid> # attaches a running docker container
$ docker container attach <cname> # attaches a running docker container
$ docker container rm <cid> # removes a container
$ docker container rm <cname> # removes a container
Executing command inside Container
$ docker container exec <cid> <cmd> # executes cmd inside container with given id
$ docker container exec <cname> <cmd> # executes cmd inside container with given name
$ docker container exec -it <cid> <cmd> # executes cmd inside container in interactive mode
$ docker container exec -it <cname> <cmd> # executes cmd inside container in interactive mode
Publishing Ports
$ docker container run -p <hport>:<cport> <iname> # publishes container port in host port
Binding directories
$ docker container run -v /p/t/hdir:/p/t/cdir <iname> # binds host dir to container dir
This repository is published under MIT License
. To know more about license please visit this link.
I'll continue to improve this repository. So, watch this repo. If you want to contribute, please read this guide.