1.下载地址:
https://github.com/docker/compose/releases
找个版本,可以直接下载到本地,上传或者命令直接下载
linux下载
curl -L https://github.com/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
下载下来就是个docker-compose文件
2.授权可执行权限:
chmod +x docker-compose
3.验证:
docker-compose version
4.编写文件:
vi docker-compose.yml
version: "3"
services:
tomcat:
restart: always
image: tomcat
container_name: tomcat
ports:
- 8080:8080
volumes:
- /usr/local/docker/myshop/ROOT:/usr/local/tomcat/webapps/ROOT
mysql:
restart: always
image: mysql:5.7.22
container_name: mysql
ports:
- 3306:3306
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: 123456
command:
--character-set-server=utf8mb4
--collation-server=utf8mb4_general_ci
--explicit_defaults_for_timestamp=true
--lower_case_table_names=1
--max_allowed_packet=128M
--sql-mlde="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO"
volumes:
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
5.启动 docker-compose up
docker ps -a
6.停止 docker-compose down
docker-compose命令必须在有docker-compose.yml文件目录下执行
7.守护进程执行 docker-compose up -d
8.查看日志 docker-compose logs -f tomcat