Reputation: 1079
Currently when we update a Docker Swarm service, we just run the relevant command in each environment. So for example if we need to add a mount to an external folder, we just run "docker service --mount-add ..." in test and production.
However this seems to not be consistent with the infrastructure-as-code idea. Currently it would be hard to reproduce any running Docker Service, and we rely on documentation to known how these services are configured.
Is there something available in Docker Swarm to avoid this problem? So I would like to specify my service-configuration inside a configuration file, and have Docker Swarm update the configuration based on this config file. So when using the same "config"-file in each environment I'm sure they are all the same, and this file becomes the documentation.
Upvotes: 5
Views: 5774
Reputation: 5644
You should declare your swarm service(s) using Docker Compose files, and then deploy them to your swarm. For example, here's a simple Compose file that runs the nginx image as a service named nginx
version: '3.6'
services:
nginx:
image: nginx:stable-alpine
ports:
- 80:80
Then, you use docker stack deploy to deploy this Compose file and all the services and other resources defined in it as a stack.
docker stack deploy --compose-file the-compose-file.yml demo
When you have an update for the service, change the Compose file, and then deploy it again with the same stack namespace (demo
in the example above). Docker will update the previously deployed service.
Upvotes: 6