You are on page 1of 1

DOCKER

Orchestrate Clean Up
Commands : ■ To clean up unused/dangling images:
■ To initialize swarm mode and listen to a specific interface: Docker image prune
Docker swarm init --advertise-addr 10.1.0.2 ■ To remove images not used in containers:

CHEAT SHEET
■ Join an existing swarm as manager node: Docker image prune -a
Docker swarm join --token<manager-token> 10.1.0.2:2377 ■ To prune the entire system:
■ Join a swarm as a worker node: Docker system prune
Docker swarm join --token<worker-token> 10.1.0.2:2377 ■ To leave a swarm:
■ List all the nodes in the swarm: Docker swarm leave
Docker node ls ■ To remove a swarm:
Docker ■ Create a service from an image and deploy 3 instances: Docker stack rm stack_name
Docker service create --replicas 3 -p 80:80 name -webngix ■ To kill all running containers:
Docker tool was introduced in order to make it easier for you to create, ■ List services running in the swarm: Docker kill $ (docker ps -q)
deploy, and run applications using containers. Containers provide you the Docker service ls ■ To delete all stopped containers:
packaging of your application with all the important components it ■ Scale a service: docker rm $(docker ps -a -q)
requires, like libraries and other dependencies, and ship them all out as one Docker service scale web=5 ■ To delete all images:
package. Due to this, you as a developer can be assured that your ■ List tasks of a service: docker rmi $(docker images -q)
application will run on any other machine. Docker service ps web
Services
Build
Docker Architecture List of all services running in a swarm:
● Registry - hosts the public and official images ■ To build the image from the docker file and tag it: Docker service ls
● Images - can be downloaded from the registry directly or implicitly when Docker build -t myapp :1.0 To see all running services:
starting a container ■ List all images that are locally stored: Docker stack services stack_name
● Containers - instances of images. Multiple containers for a single image is Docker images To see all service logs:
possible. ■ Delete an image from the docker store: Docker service logs stack_name service_names
● Docker daemon - creating, running and monitoring containers, building Docker rmi alpine: 3.4 To scale service across qualified nodes:
and storing images Docker service scale stack_name_service_name= replicas
● Client - talks to daemon via http Run
Interaction Within a Container
■ To create and run a command:
Docker run --name container_name docker_image
■ Flags used: Run a command in the container:
Docker exe -ti container_name command.sh
-d detach container on start
-rm remove container once it stops Follow the container logs:
-p publish host ip and host port to the container por Docker logs -ft container name
Save a running container as an image:
-v define and share volume across containers
--read-only sets it to read only permission Docker commit -m “commit message” -a “author” container_name
username/image_name: tag
Ship
Important Terms
■ To pull an image from the registry: ■ Log in to a registry:
• Layer - read-only files to provision the • Registry/hub - the central place where
Docker pull alpine:3.4. Docker login
system images live
■ Retag a local image with a new image my.registry.com:8000
• Image – a read only layer that is the • Docker machine - a VM to run docker
name: ■ Push an image to a registry:
base of the image containers
Docker tag alpine:3.4 myrepo/ Docker push myrepo/
Furthermore:
• Container - a runnable instance of the • Docker compose - a VM to run
myalpine:3.4 myalpine:3.4
Docker Training Course image multiple containers as a system

You might also like