Skip to main content

Quick Commands

Show running container

docker ps

Run new container

(Also pulls the corresponding image)

docker run -d -t -p <portondockerhost>:<portinsidedockercontainer> --name <containername> <containerimagename>:<containerimageversion>

Docker arguments

ArgumentMeaningImpactExample

-i

interactive

Returns output directly to prompt from Docker

docker run -i hello-world

-d

detached

The container is executed in the background

docker run -d hello-world

-p

port

Can pass a port from the host to container (hostport:containerport)

docker run -p 80:80 hello-world

-v

volume mapping

Can mount an external directory

docker run -v http://opt/datadir:/var/lib/mysql hello-world

-e

environment variableThis dash can be used to pass variables to the containerdocker run -e NEW=1 hello-world

Download specific container image

docker pull <imagenamefromdockerhub>:<imageversion>

Power options for container

Stop container

docker stop <containername/containerid>

Start container

docker start <containername/containerid>

Restart Container

docker restart <containername/containerid>

Show statistics

docker stats

Delete all stopped container

docker system prune

Show container details

docker inspect <containername/containerid>

Return specific ip address of container

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <containername/containerid>

Show container logs

docker logs <containername/containerid>

Update container restart behavior

docker update --restart unless-stopped <containername/containerid>