Docker Swarm lets you manage a group of Docker hosts as a single, virtual system which is essential for managing multiple machines. The following steps illustrate how to deploy a Docker Swarm orchestrator on multiple machines.
1. Install Docker: Ensure Docker is installed on all your machines that you want to be part of the Swarm. Docker can be installed by following the instructions on their official website: https://docs.docker.com/get-docker/.
1. Initialize the swarm: On your first machine, run the following command:
```
docker swarm init —advertise-addr
```
Replace `
1. Add nodes to the swarm: Use the second machine now. Run the command that was output by the `docker swarm init` on the second machine. The command will look like this:
```
docker swarm join —token SWMTKN-1-xxxxxxxxxxxxx-xxx
```
Repeat this step on any additional machines you want to add to the Swarm. Your Docker Swarm is now set up.
1. Deploy a service to the swarm: Now that Docker Swarm is set up, you can deploy a service. Here’s an example of how to deploy a basic nginx server:
```
docker service create —replicas 1 —name helloworld alpine ping docker.com
```
This creates a service called `helloworld` that runs the command `ping docker.com` in an `alpine` Docker container. The `—replicas 1` flag indicates that one instance of this service should be running across the swarm.
1. View the status of deployed services: The `docker service ls` command shows you how many replicas of each service are running:
```
docker service ls
```
Remember, Docker Swarm only works on Docker 1.12 and higher. This means you need to upgrade Docker on any machine where Docker is below this version. Also, you may need to open certain network ports to make sure nodes can communicate.
Specifically, the following ports should be available. On workers nodes: TCP port 2377 for cluster management communications, TCP and UDP port 7946 for communication among nodes, and UDP port 4789 for overlay network traffic.
On manager nodes: TCP port 2377 for communication between the Docker nodes, and TCP and UDP port 7946 for inter-node communication.