The student will be tasked to work with Docker and configure one management node and one client node, with the Docker service running. They will then need to add the client node to a swarm cluster and work with services across the swarm.
Successfully complete this lab by achieving the following learning objectives:
- Initialize your Master Node
Before you can create a service, you have to initialize the swarm master. You can accomplish this via:
docker swarm init
NOTE: Be sure to capture the output of the command so that you can use it on your node to register with the master!
- Register Your Node with the Swarm Master
Once the master has been initialized, you will have captured the ‘join’ command containing the token you need. The command will look something like this. You will run the following command on the second server in your configuration:
docker swarm join --token SWMTKN-1-3pu6hszjas19xyp7ghgosyx9k8atbfcr8p2is99znpy26u2lkl-7p73s1dx5in4tatdymyhg9hu2 192.168.99.121:2377
NOTE: Your token string AND IP will differ for your lab, this is an example of the command you will run
- Create the Service in Your Swarm
Be sure you download the image you plan to work with:
docker pull httpd
Now, on the master server, you can run the following command to run your service:
docker service create --name our_api --replicas=2 httpd:latest
This will create a service with two replicas, one running on each node in the swarm