Docker-compose简介
Docker-compose 是用于定义和运行多容器的 Docker 应用程序的工具。通过 Compose,可以使用 YAML 文件来配置应用程序的服务。
Linux下安装Docker-compose
https://github.com/docker/compose/releases
1
| curl "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
|
更改权限:chmod +x /usr/local/bin/docker-compose
查看版本:docker-compose version
Docker-compose常用命令
- 查看配置:docker-compose config
- 后台启动:docker-compose up -d
- 停止并删除容器、网络、卷、镜像: docker-compose down
- 构建镜像:docker-compose build
- 下载镜像:docker-compose pull
- 展示当前docker-compose编排过的运行的所有容器:docker-compose ps
- 进程:docker-compose top
- 查看配置:docker-compose config
- 启动:docker-compose start
- 停止:docker-compose stop
Docker-compose.yml示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| version: "3"
service: microService: image: docker_image:1.6 container_name: ms_01 ports: - "6001:6001" volumes: - /app/microService:/data networks: - atguigu_net depends_on: - redis - mysql redis: image: redis:6 ports: - "6379:6379" volumes: - /app/redis/redis.conf:/etc/redis/redis.conf networks: - atguigu_net command: redis-server /etc/redis/redis.conf mysql: image: mysql:5.7 environment: MYSQL_ROOT_PASSWORD: '123456' MYSQL_ALLOW_EMPTY_PASSWORD: 'no' MYSQL_DATABASE: 'db123' MYSQL_USER: 'william' MYSQL_PASSWORD: '123456' ports: - "3306:3306" volumes: - /app/mysql/mysql.conf:/etc/mysql/mysql.conf networks: - atguigu_net command: --default-authentication-plugin=mysql_native_password networks: atguigu_net:
|