Docker - Create stacks using the docker stack deploy command

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

version: "3.7"
    image: foo:latest
    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.

r0zassvat4e5  stack001_default  overlay  swarm


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

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          
kod8l0fc9alv        stack001_bar         replicated          1/1       



Did you find this article helpful?

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

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

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