Detailed guide to docker container management with portainer and docker swarm

Tram Ho

I, Preamble

In the previous post, I also wrote a tutorial on Using Portainer to manage Docker apps such as installing docker swarm, joining node or deploying docker stack, … the docker is managed by Portainer as well as using portainer effectively for the project.

II, Main content

1. What is Stack in Portainer?

Sure, when learning about docker, you already know the concept of docker-compose and have used it. Of course, when using the docker stack you will also ask questions about the docker compose because they are similar, but there are many differences in particular: Docker Compose and Docker stack can both be controlled by a docker-compose.yml file docker-compose.yml

  • Docker Compose: is a tool (official tool) that helps you manage docker containers by what is written in a docker-compose.yml file.

  • Docker stack: is a command embedded in the Docker CLI. It will help you manage a docker container through the docker swarm.

However, in some cases some features will only work with the docker stack, while the docker-compose will ignore it. And similarly, unsupported docker-compose are ignored by the docker stack command.

For example, the deploy attribute is removed from the docker compose and the depends_on attribute is removed by the docker stack . If you need more information you can refer to Compose file reference. . And you can say the docker stack is a great improvement if you use docker-compose in development and use the Docker swarm in production.

And in a project, the docker stack can be understood as a group of services that are related to each other and managed on the same Docker CLI.

2. How do I create a stack?

To create a stack, you need to have a docker compose file ready. As I have compared above, some properties of docker-compose will not be supported by docker-stack so when writing or refactor docker-compose.yml pay attention. A docker-composer file of the stack will contain all the services you want to put on the stack, possibly services:

  • php-fpm,
  • mysql,
  • redis, …

After you have added the content docker-compose file to the box, you can create a stack already. Similar to using the docker stack deploy docker-compose.yml command docker stack deploy docker-compose.yml =))

3. What is Services in portainer?

Services is a concept inside docker, as above you have define services in that docker-compose file. To deploy an image app using docker swarm, you need to create a simple service like that: v. Usually a service is the image for a microservice in a large application. For example, viblo is a large application, inside it will include services such as HTTP server, database, web frontend, …

With docker swarm it supports one or more replica tasks, so each service will contain one or more replica containers depending on our monitor.

In the service we can add environments, network connect, config, … for all replica containers, we can optionally change the number of replicas too. Besides, when updating the config, all the containers in it will be updated as well.

4. What are Containers in Portainer?

This is the place to manage the containers, full of actions such as checking health check, start, stop, kill, restart … like docker CLI command.

5. What are networks in portainer?

This is the place to manage docker networks, we can create networks for services and add containers to it. While on the same network, containers can ping each other. The stacks in the node can join the same network.

6. What are volumes in portainer?

This is a place for managing volumes, showing all the containers that the stacks can use. As well as creating mounted volumes into common container for containers.

7. What are the configs in portainer?

This is the place to store config files of services, containers, … For example, your project will have many services, each service will have its own .env file, you will create the corresponding file of the service here. Centralized config file management has advantages:

  • Can be modified without rebuilding stacks, services or containers …
  • Can clone, copy to new file easily.
  • Avoid writing docker-compose files too long …

8. What is Secret in Portainer?

Listen to the word secret, there is also something “new” in this new secret =)). Security files like ssl-cert, private.key, … we will create here and call in the service.

III Conclusion

Surely after this article you have got the knowledge of project management with docker swarm, right. We hope to hear from you

Share the news now

Source : Viblo