Bootstrap FreeKB - Docker - Create stacks using the docker stack deploy command
Docker - Create stacks using the docker stack deploy command

Updated:   |  Docker articles

Let's say you have the following docker-compose.yml file which contains two services, foo and bar.

version: "3.7"
services:
  foo:
    image: foo:latest
  bar:
    image: bar:latest

 

The docker stack deploy command can be used to deploy or redeploy (update) the stack.

docker stack deploy --compose-file docker-compose.yml stack001

 

A Docker image contains the code used to create a Docker container, such as creating a Nginx web server, or a mySQL server, or a home grown app, and the list goes on. In this way, an image is like a template used to create a container. An image is kind of like a virtual machine, but much more light weight, using significantly less storage a memory (containers are usually megabytes in size).

 

There are various ways to pull down an image:

  • Using the docker pull command (as-is image as-is is pulled down)
  • Using the docker run command (as-is image is pulled down and container is created/started)
  • Using the docker build command (image can be customized)
  • Using the docker stack deploy command (Docker Compose)

 

If this is the first deploy of the stack, and the deploy is successful, something like this should be returned.

Creating network stack001_default
Creating service stack001_foo
Creating service stack001_bar

 

The docker network ls command can be used to confirm that the stack001_default network was created.

NETWORK ID    NAME              DRIVER   SCOPE
r0zassvat4e5  stack001_default  overlay  swarm

 

The docker stack ls command can be used to confirm that the stack was created.

NAME       SERVICES  ORCHESTRATOR
stack001   2         Swarm

 

The docker stack services command can be used to confirm that the foo and bar services were created.

ID                  NAME                   MODE              REPLICAS            IMAGE
ivq9h5yxl1om        stack001_foo         replicated          1/1                 registry.example.com/stack001_foo:latest   
kod8l0fc9alv        stack001_bar         replicated          1/1                 registry.example.com/stack001_bar:latest

 

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 4b1701 in the box below so that we can be sure you are a human.