Deploy Applications With Docker Compose

When deploying complex solutions and applications with Docker, there is a need to create structure and order in the deployment.

Docker-compose allows us to deploy applications that have dependencies or rely on other services that run inside other containers.

A good example is WordPress. Deploying WordPress with Docker-Compose is ideal because WordPress is an app that depends on a database service. It is probably a good idea to deploy both together using compose.

How to use Docker Compose

To use Docker compose, we need the following:

  • Docker Compose (Installed by default with Docker Desktop)
  • Create a directory that will act as the name of the application
  • Create a file called docker-compose.yml


Let use a simple example for our deployment. Below I am deploying an application with two containers (webapp and backend ). The webapp container runs Nginx, and the backend run MySQL DB.

    image: nginx
      - "80:80"
    image: mysql:5.7
      - data:/var/lib/mysql
    restart: always
      MYSQL_DATABASE: needed
      MYSQL_USER: needed
      MYSQL_PASSWORD: needed
  data: {}

I’m also attaching a volume for the MySQL DB to save data to the hosts.

To run the application, I will run the following command from the directory of the application.

docker compose up

Once the application is running, I can see it from VS Code

Since port 80 is open via the docker-compose.yml file, I can access the app from my browser.

To shut down the application and delete all the containers run.

docker compose down






2 responses to “Deploy Applications With Docker Compose”

  1. […] the example below taken from a docker-compose.yml file, we create a named volume called data in line number 5. The volume will map to the […]

  2. […] To use Docker Compose, please check this post. […]