Wood Chen

How to Deploy with Docker Compose

0 comments67 views177 words

This post was translated from Chinese by AI. If anything reads oddly, the Chinese original is authoritative. 中文原文

Deploying with Docker Compose involves the following steps:

  1. Write a docker-compose.yml file.
    This file defines the services and containers for the application you want to run. In it, you can specify Docker images, port mappings, volumes, and more.
  2. Start the containers with Docker Compose.
    In your terminal, navigate to the directory containing docker-compose.yml, then run docker-compose up to start all the containers.
  3. Check that the application is working properly.
    Use a browser or other tools to check that the containers have started and are running.
  4. Stop and remove the containers.
    When you finish testing and development, stop and remove the containers to free up resources. Run docker-compose down in your terminal to stop and remove them.

Here is a simple example:

version: '3'
services:
  web:
    build: .
    ports:
      - "5000:5000"
  redis:
    image: "redis:alpine"

In this example, we define two services: web and redis. The web service is built from the current directory and runs with port 5000 exposed. The redis service uses the official Redis image from Docker Hub. We can then start these containers by entering docker-compose up in the terminal.

Last updated 2024-01-14

Related posts

Comments 0