// Run docker image in interactive mode
docker run -it <image name>:<image tag>
// Run docker image in interactive mode with host port 8080 mapped to container port 80
docker run -it -p 8080:80 <image name>:<image tag>
// Run docker with the 3001 port exposed,
docker run -it --expose=3001 <image name>:<image tag>
// Run docker with an environment variable set
docker run -it \
-e RUST_BACKTRACE=1 \
<image name>:<image tag>
// Run a docker command in container and remove container after finish
docker run --rm -it --expose=3001 <image name>:<image tag>
// Check the process running inside the container
docker top <container name or id>
// Check resource utilization
docker stats
// Check docker logs with multiple time options
docker logs -f --since <1s|5m|1d|UTC date time> <container name>
// Start and stop a container by name
docker start <container name>
docker stop <container name>
// Update container configurations
docker update --restart=always <container name>
docker update --kernel-memory 80M <container name>
// Inspect container configurations
docker inspect
// docker system information
docker system df (Show disk info)
docker system events (Show system events)
docker system info (Show system info)
docker system prune (Prune unused data)
https://docs.docker.com/engine/reference/run/
With the new docker reoragnisation of modules, all commands are re-structured similar to Kubernetes. E.g.
Below 2 are same:
docker run -it -e RUST_BACKTRACE=1 <image name>:<image tag>
docker container run -it -e RUST_BACKTRACE=1 <image name>:<image tag>
And so are the below 2 commands to list containers,
docker ps -a
docker container ls
docker rm $(docker ps -q -f 'status=exited')
docker rmi $(docker images -q -f "dangling=true")
docker volume rm $(docker volume ls -qf dangling=true)
docker images | grep <pattern> | xargs docker rmi
docker inspect $container_id | $container_name
https://www.ctl.io/developers/blog/post/docker-networking-rules/
docker system prune
Or
docker container prune
docker image prune
docker network prune
docker volume prune
https://stackoverflow.com/a/32723127/3878940
Try any of
docker run -it --rm alpine /bin/ash
docker run -it --rm alpine /bin/sh
docker run -it --rm alpine ash
docker run -it --rm alpine sh
- Docker cheat sheet: https://github.com/wsargent/docker-cheat-sheet
- Docker plugin for zsh: https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins#docker