专业的编程技术博客社区

网站首页 > 博客文章 正文

docker compose 常用配置,备份收藏

baijin 2024-09-17 12:11:30 博客文章 3 ℃ 0 评论

Docker Compose 使用 docker-compose.yml 文件来定义和配置整个应用程序的服务、网络、卷等。以下是一些常用的 Docker Compose 配置选项和示例:
1. 定义服务:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
  • version: Docker Compose 文件的版本。
  • services: 定义应用程序的各个服务。

2. 多个服务:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
  database:
    image: mysql:latest
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: mydatabase

3. 挂载卷:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
    volumes:
      - ./html:/usr/share/nginx/html

4. 环境变量:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
    environment:
      NGINX_HOST: example.com

5. 网络:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
    networks:
      - mynetwork

networks:
  mynetwork:

6. 配置依赖关系:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
  database:
    image: mysql:latest
    depends_on:
      - web
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: mydatabase

7. 多容器定义:

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "8080:80"
  app:
    image: myapp:latest
    ports:
      - "5000:5000"

这些示例只是 Docker Compose 配置的一小部分,具体的配置取决于你的应用程序需求

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表