The difference between Docker Compose and Docker Stack

The difference between Docker Compose and Docker Stack

1 Overview

In the most recent release, something happened in the Docker circle. The Swarm mode has been integrated into Docker Engine in 1.12 and has brought us several new tools. Among them, we can use the docker-compose.yml file to provide a stack of Docker containers without installing Docker Compose.

This command is docker stack, and it looks exactly the same as docker-compose. This is a comparison of their usage:

$ docker-compose -f docker-compose up

$ docker stack deploy -c docker-compose.yml somestackname

They are indeed very similar. Both of these will provide all services, volumes, networks, and everything else, as specified in the docker-compose.yml file. But why is this, and how is docker stack different from Docker Compose? Why introduce it? In addition to grammar, what else do we need to know?

2. The difference

Docker stack will ignore the "build" instruction. You cannot use the stack command to build a new image. It requires that the image is pre-built. So docker-compose is more suitable for development scenarios.

There are also some compose-file specifications that are ignored by docker-compose or stack commands. (Search for "ignore" to see more details).

Docker Compose is a Python project. Initially, there was a Python project called fig to parse the fig.yml file, you guessed it-the Docker container for the stack. Everyone likes it, especially the followers of Docker, and finally it slowly integrated into the docker product. But it is still in Python, running on the Docker engine.

Internally, it uses the Docker API specification to operate containers. So you still need to install Docker-compose separately in order to use it with Docker on your computer.

The Docker Stack function is included in the Docker engine. You don't need to install additional packages to use it, docker stacks are only part of swarm mode. It supports the same types of compose files, but the actual processing takes place in the Go code inside the Docker Engine. Before using the stack command, a stand-alone version of "swarm" must be created, but this is not a big problem.

If your docker-compose.yml is based on the second version (specify version: "2" in docker-compose.yml), then Docker stack is not supported. You must use the latest version, that is, the version version is at least 3. However, Docker Compose can still process files with versions 2 and 3.

3. Summary

In version 3, both docker-compose and the new docker stack command can handle the docker-compose.yml file. For the version 2 .yml file, you have to continue to use the docker-compose command. If you want to upgrade, you don't need to do much work.

Since docker stack has done all the work of docker compose, it is certain that docker stack will dominate. This means that docker-compose may be deprecated and will not be supported eventually.

However, for most users, switching to using docker stack is neither difficult nor does it require much overhead. You can easily upgrade docker compose from version 2 to version 3.

If you are new to Docker, or are choosing a technology for new projects, please boldly use docker stack deployment

Original link: https://vsupalov.com/difference-docker-compose-and-docker-stack/

Guess you like

Origin blog.csdn.net/weixin_41191813/article/details/113483975