Deploy with Docker stack

Create your docker-compose file.

Ensure it’s stating a version of at least 3.

Initiate swarm

You can only deploy to a swarm. So when you’re not on a swarm yet, initiate a swarm.

Deploy the stack

Check the status of your stack

To check the status of the services in your stack, issue the command docker stack ps <stackname>.

Check services in your stack

Get more detailed info of a service with docker service ps

Get the full errormessage. Because, by default, it’s truncated. No prob, just use the --no-trunc flag

Services use containers too

The services use containers too. This knowledge can help if you need to debug and want to execute a command on one of the containers.

The containers have really long names. I prefer to use a little helperscript to make executing commands on containers easier.

Now when I want to execute a command on a container with ‘app’ in the name, I use that as the first argument. So the command becomes ./dev <part_of_container_name> <command_to_execute_on_container>

Update the stack

If there are changes to the images, you can update your stack by simply running the deploy again.

Getting the logs for a service

To debug your stack, you can use docker service logs to see what happens on the service.

Remove the stack

To remove your stack, use the rm flag.