Download Docker Commands Cheat Sheet and more Cheat Sheet Operating Systems in PDF only on Docsity! Docker Commands
Cheat Sheet
‘bal
a
Tals 08 youre container name ete
‘sing Docker
—_ ——_
docker cornions fey omecrrer fe{suncommaobed Ano.
Orchestration
To creete and run a container:
docker run --name container_name docker_image
Other useful flags to attach to the ‘docker run’ commandare:
-a@ —Delach container on start
-xm — Remove container once it stops
-p — Publishhost IP and host port to the container port
-v_—Define and share storage volume across containers
--read-only — Sets container to be read only
Clean Up
To clean—or prune—unused (dangling) images:
docker image prune
To remove all images which are not in use by containers, add -a:
docker image prune -a
To prune your entire system:
docker system prune
To leave a swarm:
docker swarm leave
To remove a swarm: (Deletes all volume data and database info also!)
docker stack rm stack_name
To kill all running containers:
docker kill $(docker ps -q)
To create and run a container:
docker run --name container name docker_image
Other useful flags:
-d —Detach container on start
-rm — Remove container once it stops
-p — Publish host IP and host port to the container port
-v_ —Define and share volume across containers
--read-only — Sets container to be read only
Build
To pull an image from the Registry, define ‘image_narne’:
docker pull image_name:tag
To build an image from your Dockerfile:
docker build -t image _name:tag
If you don’t want your container to autostart, use:
docker create--name container_name image_name:tag
Start and stop container commands:
docker start container_name
docker stop container name
Services
To view a list of all the services running in a swarm:
docker service ls
To see all running services:
docker stack services stack_name
To see all service logs:
docker service logs stack_name_service_ name
To scale services quickly across qualified nodes:
docker service scale stack_name_service_name=replicas