If you don’t already know, Docker is an open-source platform for building distributed software using “containerization,” which packages applications together with their environments to make them more portable and easier to deploy.
Docker Commands and Best Practices
Before we get into the best practices for using Docker, here’s a quick overview of the vocabulary you should know:
Layer: a set of read-only files or commands that describe how to set up the underlying system beneath the container. Layers are built on top of each other, and each one represents a change to the filesystem.
Image: an immutable layer that forms the base of the container.
Container: an instance of the image that can be executed as an independent application. The container has a mutable layer that lies on top of the image and that is separate from the underlying layers.
Registry: a storage and content delivery system used for distributing Docker images.
Repository: a collection of related Docker images, often different versions of the same application.
Below, you’ll find all of the basic Docker commands that you need to start working with containers:
docker stop $(docker ps -a -q) && docker rm $(docker ps -a -q)
Removing Dangling Volumes
docker volume rm $(docker volume ls -f dangling=true -q)
Docker Swarm
Installing Docker Swarm
curl -ssl https://get.docker.com | bash
Initializing the Swarm
docker swarm init --advertise-addr 192.168.100.1
Getting a Worker to Join the Swarm
docker swarm join-token worker
Getting a Manager to Join the Swarm
docker swarm join-token manager
Listing Services
docker service ls
Listing nodes
docker node ls
Creating a Service
docker service create --name example -p 8080:80 sysaix/example
Listing Swarm Tasks
docker service ps
Scaling a Service
docker service scale vote=2
Updating a Service
docker service update --image sysaix/example:movies example
docker service update --force --update-parallelism 1 --update-delay 30s nginx
docker service update --update-parallelism 5--update-delay 2s --image sysaix/example:indent example
docker service update --limit-cpu 2 nginx
docker service update --replicas=5 nginx