docker-compose
到此下载docker-composehttps://github.com/docker/compose/releases/tag/1.27.4
#放到/usr/local/bin 改名和添加执行权限 (是让docker-compose成为系统命令)
mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose
chmod 755 docker-compose
yml文件
:后面有个空格
缩进适用2个空格,不能适用tab
version: '3.1'
services:
mysql: #服务名称
restart: always #和docker一起启动
image: daocloud.io/library/mysql:5.7.4 #镜像路径
container_name: mysql_con #容器名称
ports:
- 3305:3306 #指定端口号映射
environment:
MYSQL_ROOT_PASSWORD: root #设定登录密码
TZ: Asia/Shanghai
volumes:
- /data/mysql/data:/var/lib/mysql #映射数据卷
tomcat:
restart: always
image: daocloud.io/library/tomcat:8.5.15-jre8
container_name: tomcat_con
ports:
- 8085:8080
environment:
TZ: Asia/Shanghai
volumes:
- /data/tomcat/data:/usr/local/tomcat/webapps
- /data/tomcat/logs:/usr/local/tomcat/logs
docker-compose配置dockerfile
docker-compose.yml
version: '3.1'
services:
ssd:
restart: always
build:
context: ./ #指定dockerfile路径
dockerfile: Dockerfile
image: ssd:1.1.1
container_name: ssd
ports:
- 8083:8080
environment:
TZ: Asia/Shanghai
Dockerfile
from daocloud.io/library/tomcat:8.5.15-jre8
copy index.html /usr/local/tomcat/webapps/ROOT/
docker-compose.yml和Dockerfile和index.html放到同一路径,执行下面指令
#如果没有镜像就创建,有就直接运行
docker-compose up -d
重新生成镜像
docker-compose up -d --build