Here’s a quick tip on how to convert docker-compose.yml file to a Docker Swarm mode ready file.

the command

Imma be straight to the point and share few commands to help you with converting a Docker Compose stack config to a Docker Swarm mode one:

docker stack config --compose-file docker-compose.yml > swarm.yml

To deploy it, run:

docker stack deploy --compose-file swarm.yml my-service

Notes:

  • Replace my-service with your preferred stack name
  • Use -c for shorthand for --compose-file

.env file

When your setup relies on .env file, you’ll need to export the variables before deployment since Docker Swarm doesn’t automatically load .env files:

export $(cat .env) > /dev/null 2>&1; docker stack deploy my-service --compose-file=docker-compose.yml

One of the weakest points by Docker Swarm mode tho.

alternative direct deployment

For simple cases, you can skip the conversion step and deploy directly:

docker stack deploy my-service --compose-file docker-compose.yml

Docker will handle the conversion internally, though generating the swarm file first gives you more visibility into the final configuration.

bottom line

Shameless plug: Check out justanotheruptime.com in case you are looking for a SaaS monitoring solution :)