Skip to content

Instantly share code, notes, and snippets.

@musab
Created January 20, 2022 14:00
Show Gist options
  • Save musab/c7c561ece7ea17201656ac4c719e65b0 to your computer and use it in GitHub Desktop.
Save musab/c7c561ece7ea17201656ac4c719e65b0 to your computer and use it in GitHub Desktop.
docker commands cheatsheet

Run a docker image

docker run nginx

Run a specific tag of a docker image

docker run redis:4.0

List all running containers

docker ps

List ALL containers

docker ps -a

Stop container

docker stop <containerID>

Remove container

docker rm <containerID>

List all images

docker images

Remove image

docker rmi <image>

Download image

docker pull <image>

Append a command

docker run ubuntu sleep 5

Execute a command inside container

docker exec <containerID> cat /etc/hosts

Run detached (background)

docker run -d <image>

Re-attach to terminal

docker attach <containerID>

Interactive mode

docker run -i <image>

Interactive with terminal

docker run -it <image>

Mapping Port

docker run -p 80:5000 <image>

Mapping folder

docker run -v /opt/datadir:/var/lib/mysql <image>

Inspect container

docker inspect <containerID>

Logs

docker logs <containerID>

Environment variables

docker run -e APP_COLOR=green simple-webapp-color

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment