Docker Community Forums

Share and learn in the Docker community.

How to start containers using docker-compose.yml file from the server


I have four images built using docker-compose.yml. I start the container using docker-compose up -d on my local. I have pushed these images to docker hub and pulled from the server where i want to host my site. As of now i start the container by using docker run on 4 of the images. How can i start all the containers as i did in local using docker-compose up in the server.
Any help is really appreciated as i’m novice in this field

Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration. To learn more about all the features of Compose, see the list of features.

Compose works in all environments: production, staging, development, testing, as well as CI workflows. You can learn more about each case in Common Use Cases.

Using Compose is basically a three-step process:

Define your app’s environment with a Dockerfile so it can be reproduced anywhere.

Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.

Run docker-compose up and Compose starts and runs your entire app.

A docker-compose.yml looks like this:

version: “3.8”
build: .
- “5000:5000”
- .:/code
- logvolume01:/var/log
- redis
image: redis
logvolume01: {}

I have done all this and it is working perfect in my local machine. All i want to know is how i can run the images which is pulled to the server from dockerhub using the docker-compose.yml file

Hi There,
You can use docker stack to deploy your services on server using your docker-compose.yml file. Docker stack deploy takes docker-compose as its declarative input to deploy services on sever.

Docker stack deploy -c docker-compose.yml (prefix for your stack)

Note: To use docker stack, first enable swarm mode on docker on your server using ‘docker swarm init’ command.

Thank you my slot friend i thing so :DDDD