当前位置: 首页 > article >正文

docker-compose文件的简介及使用

一、docker-compose 文件整合多个项目配置

version: '3.8'

services:
  # MySQL 数据库服务
  mysql:
    image: mysql:5.7  # 使用官方的 MySQL 镜像,版本为 5.7
    container_name: my_mysql
    environment:
      TZ: Asia/Shanghai
      MYSQL_ROOT_PASSWORD: root_password  # 设置 root 用户的密码
      MYSQL_DATABASE: mydb  # 创建一个名为 mydb 的数据库
      MYSQL_USER: myuser  # 创建一个名为 myuser 的用户
      MYSQL_PASSWORD: mypassword  # 设置 myuser 用户的密码
    volumes:
      - "./mysql/data:/var/lib/mysql"
      - "./mysql/conf:/etc/mysql/confi.d"
      - "./mysql/init:/docker-entrypoint-initdb.d"
    ports:
      - "3306:3306"  # 将宿主机的 3306 端口映射到容器的 3306 端口
    networks:
      - my_net
aipro:
  build:			# 根据Dockerfile文件构建镜像
    context: .
    dockerfile: Dockerfile
  container_name: aipro
  ports:
      - "8080:8080" # 将宿主机的 8080 端口映射到容器的 8080 端口(根据你的后端应用配置调整)
  networks:
      - my_net
  depends_on:
      - my_mysql  # 确保 MySQL 服务先启动
  # Nginx 服务,用于反向代理前端和后端
nginx:
    image: nginx:latest  # 使用官方的 Nginx 镜像,版本为 latest
    container_name: my_nginx
    volumes:
      - "./nginx/nginx.conf:/etc/nginx/nginx.conf"  # 使用自定义的 Nginx 配置文件
      - "./nginx/frontend/dist:/usr/share/nginx/html"  # 将前端应用的静态文件映射到 Nginx 的默认根目录
    ports:
      - "80:80"  # 将宿主机的 80 端口映射到容器的 80 端口
    depends_on:
      - aipro  # 确保后端服务先启动(如果 Nginx 需要代理到后端)
    networks:
      - my_net
networks:
  my_net:
    name: aipro
MacBook-Pro:dockercompose jd$ docker compose --help

Usage:  docker compose [OPTIONS] COMMAND

Define and run multi-container applications with Docker

Options:
      --all-resources              Include all resources, even those not used by services
      --ansi string                Control when to print ANSI control characters ("never"|"always"|"auto") (default "auto")
      --compatibility              Run compose in backward compatibility mode
      --dry-run                    Execute command in dry run mode
      --env-file stringArray       Specify an alternate environment file
  -f, --file stringArray           Compose configuration files(指定compose文件的路径和名称)
      --parallel int               Control max parallelism, -1 for unlimited (default -1)
      --profile stringArray        Specify a profile to enable
      --progress string            Set type of progress output (auto, tty, plain, json, quiet) (default "auto")
      --project-directory string   Specify an alternate working directory
                                   (default: the path of the, first specified, Compose file)
  -p, --project-name string        Project name

Commands:
  attach      Attach local standard input, output, and error streams to a service's running container
  build       Build or rebuild services
  config      Parse, resolve and render compose file in canonical format
  cp          Copy files/folders between a service container and the local filesystem
  create      Creates containers for a service
  down        Stop and remove containers, networks(停止并移除所有所有容器)
  events      Receive real time events from containers
  exec        Execute a command in a running container(在一个运行的容器中执行命令)
  images      List images used by the created containers
  kill        Force stop service containers
  logs        View output from containers (查看指定容器的日志)
  ls          List running compose projects
  pause       Pause services
  port        Print the public port for a port binding
  ps          List containers(列出所有的容器)
  pull        Pull service images
  push        Push service images
  restart     Restart service containers
  rm          Removes stopped service containers
  run         Run a one-off command on a service
  scale       Scale services 
  start       Start services
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop services
  top         Display the running processes
  unpause     Unpause services
  up          Create and start containers(创建并启动所有容器)
  version     Show the Docker Compose version information
  wait        Block until containers of all (or specified) services stop.
  watch       Watch build context for service and rebuild/refresh containers when files are updated

Run 'docker compose COMMAND --help' for more information on a command.
  • 实战操作
docker compose up -d
docker compose ps

http://www.kler.cn/a/412342.html

相关文章:

  • Spring 框架中AOP(面向切面编程)和 IoC(控制反转)
  • Linux lsof
  • 第十六届蓝桥杯模拟赛第二期题解—Java
  • 正则表达式灾难:重新认识“KISS原则”的意义
  • 【TEST】Apache JMeter + Influxdb + Grafana
  • 项目进度计划表:详细的甘特图的制作步骤
  • Git 使用技巧
  • 鸿蒙开发异步与线程
  • 使用Cmake导入OpenCV库的大坑记录
  • 如何将 GitHub 私有仓库(private)转换为公共仓库(public)
  • 反爬虫机制
  • 【大数据学习 | Spark-SQL】SparkSession对象
  • 从ETL到DataOps:WhaleStudio替代Informatica,实现信创化升级
  • 计算机网络 实验八 应用层相关协议分析
  • 【NOIP普及组】表达式求值
  • 学习threejs,设置envMap环境贴图创建反光效果
  • Qt程序发布及打包成exe安装包
  • 微信小程序首页搜索框的实现教程
  • idea_常用设置
  • RSA算法和AES算法,哪种更安全
  • 电脑自动关机时间如何定?Wise Auto Shutdown 设置关机教程
  • C++网络编程:select IO多路复用及TCP服务器开发
  • 三格电子—EtherNet IP转Modbus RTU网关
  • Docker安装及常用命令
  • 信息安全实验--密码学实验工具:CrypTool
  • Rust学习(九):密码生成器