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
Argument | Meaning | Impact | Example |
-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 |
-e |
environment variable | This dash can be used to pass variables to the container | docker 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>
Return logs live to console
docker logs --follow <containername/containerid>
Update container restart behavior
docker update --restart unless-stopped <containername/containerid>