To recall how to deploy a Swarm service, you might use a command like:
history | grep deploy
Here’s an example of a command to remove and deploy a Swarm service:
docker service rm homepage_homepage && docker stack deploy -c /home/facundo/homepage/docker-compose.yml homepage
The contents of the `docker-compose.yml` are as follows:
version: "3.3"
services:
homepage:
image: ghcr.io/gethomepage/homepage:latest
restart: always
ports:
- 3080:3000
volumes:
- /mnt/swarm/homepage:/app/config # Make sure your local config directory exists
deploy:
replicas: 1
restart_policy:
condition: on-failure
placement:
constraints: [node.role != manager]
When you run the deployment command, you might see the following output:
Ignoring unsupported options: restart Since --detach=false was not specified, tasks will be created in the background. In a future release, --detach=false will become the default. Creating service homepage_homepage
1. Command Breakdown
2. YAML File Breakdown
version: "3.3" # Specifies the version of the Docker Compose file format
services: # Defines the services that make up the application
homepage: # Name of the service
image: ghcr.io/gethomepage/homepage:latest # Specifies the Docker image to use
restart: always # This option is ignored in Swarm mode (only used in standalone Docker)
ports:
- 3080:3000 # Maps port 3080 on the host to port 3000 in the container
volumes:
- /mnt/swarm/homepage:/app/config # Mounts a volume from the host to the container
deploy:
replicas: 1 # Specifies the number of service replicas to run
restart_policy:
condition: on-failure # Defines the restart policy for failed tasks
placement:
constraints: [node.role != manager] # Ensures that the service runs only on worker nodes, not on the manager
3. Ignored Options and Output Explanation
4. Why This Works
I'd be happy to explain how this Docker Swarm deployment works and provide feedback. Let's break it down step by step:
First, here's the explanation in Dokuwiki syntax:
docker service rm homepage_homepage && docker stack deploy -c /home/facundo/homepage/docker-compose.yml homepage
docker service rm homepage_homepage: This removes the existing service named “homepage_homepage”.&&: This operator ensures the next command runs only if the previous one succeeds.docker stack deploy: This command deploys a new stack or updates an existing stack.-c /home/facundo/homepage/docker-compose.yml: Specifies the path to your Docker Compose file.homepage: This is the name of your stack.version: "3.3" services: homepage: image: ghcr.io/gethomepage/homepage:latest restart: always ports: - 3080:3000 volumes: - /mnt/swarm/homepage:/app/config deploy: replicas: 1 restart_policy: condition: on-failure placement: constraints: [node.role != manager]
version: “3.3”: Specifies the Docker Compose file version.services: Defines the services in your stack.homepage: The name of your service.image: The Docker image to use.restart: always: Ignored in Swarm mode (as noted in the output).ports: Maps port 3080 on the host to 3000 in the container.volumes: Mounts a local directory to /app/config in the container.deploy: Swarm-specific deployment options.replicas: 1: Runs one instance of the service.restart_policy: Defines when to restart the container.placement: Ensures the service doesn't run on manager nodes.docker stack deploy without removing the service first. Swarm can usually update existing services smoothly.Ignoring unsupported options: restart Since --detach=false was not specified, tasks will be created in the background. In a future release, --detach=false will become the default. Creating service homepage_homepage