docker部署项目-DockerCompose一键部署
DockerCompose一键部署
说明
Docker Compose通过一个单独的docker-compose.yml模板文件,定义一组关联的应用容器,实现多个相互关联的Docker容器的快速部署。
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.8"
services: mysql: image: mysql container_name: mysql ports: - "3306:3306" environment: TZ: Asia/Shanghai MYSQL_ROOT_PASSWORD: 123 volumes: - "./mysql/conf:/etc/mysql/conf.d" - "./mysql/data:/var/lib/mysql" - "./mysql/init:/docker-entrypoint-initdb.d" networks: - hm-net hmall: build: context: . dockerfile: Dockerfile container_name: hmall ports: - "8080:8080" networks: - hm-net depends_on: - mysql nginx: image: nginx container_name: nginx ports: - "18080:18080" - "18081:18081" volumes: - "./nginx/nginx.conf:/etc/nginx/nginx.conf" - "./nginx/html:/usr/share/nginx/html" depends_on: - hmall networks: - hm-net networks: hm-net: name: hmall
|
Docker compose命令
1
| docker compose [OPTIONS] [COMMAND]
|
类型 |
参数或指令 |
说明 |
Options |
-f |
指定compose文件的路径和名称 |
Options |
-p |
指定project名称 |
Commands |
up |
创建并启动所有service容器 |
Commands |
down |
停止并移除所有容器、网络 |
Commands |
ps |
列出所有启动的容器 |
Commands |
logs |
查看指定容器的日志 |
Commands |
stop |
停止容器 |
Commands |
start |
启动容器 |
Commands |
restart |
重启容器 |
Commands |
top |
查看运行的进程 |
Commands |
exec |
在指定的运行中容器中执行命令 |