Pre-Flight Checks
Docker
Let’s check to make sure docker and other components are installed and working correctly. First, check to make sure docker is installed.
1docker --version
You should see the installed Docker Engine or Docker Desktop version.
Docker version <current>, build <hash>
Now, let’s make sure we are able to run the busybox container.
1docker run busybox echo "hello, world!"
The command above simply echos hello, world! back to the console.
Swarm
Initialization
Initialize swarm.
1docker swarm init
You should see an output as follows.
Swarm initialized: current node (muo6bizx5z19kny0gswqm8jq4) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3qo8eradxo3oy2tjzc0odurhumk4nlpt9eoeg2gq5dwl2sh88o-bc6fpa8qeh5bsn3l0kdfip2qf 10.0.2.15:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
Service creation
Now let’s create a toy service. This service uses the current alpine container to ping the Google domain name server 8.8.8.8.
1docker service create --name demo alpine:latest ping 8.8.8.8
The output should look like the following.
av2o3juacixl7zwr36wd10zzg
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
To see which services are running.
1docker service ps demo
To see the logs of a service.
1docker service logs demo
To stop the service.
1docker service rm demo