docker 编排springCloud项目:
DockerFile常用命令详解:
命令 | 解释 |
---|
FROM | 指定基础镜像 | MAINTAINER | 作者信息 | RUN | 构建时需运行的命令 | ADD | 向镜像中添加内容 | WORKIR | 运行容器的默认目录 | VOLUME | 指定挂载目录 | CMD | 指定容器运行时的命令(替代) | ENTRYPOINT | 指定容器运行时的命令(追加) | ENV | 指定环境变量 | COPY | 类似add,将文件拷贝到镜像中 | OBUILD | 构建一个被继承Dockerfile时,会触发该命令 | | |
构建镜像命令:
docker build -f dockerFile文件 -t 镜像名:版本 路径
查看镜像的构建命令:
docker history 镜像id
docker-compose 详解:
安装:
curl -L https://github.com/docker/compose/releases/download/1.22.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose -version
常用命令详解:
version: "3.0"
services:
服务名:
build:
container_name:
depends_on:
- mysql
- 服务名
links:
- mysql
expose:
posts:
volumes/volumes_from :
environment:
springcloud微服务编排:
准备:
springcloud: Greenwich.SR1;
springboot:2.1.5;
centos:7;
docker: 20.10.8;
微服务端口:
eureka:10086
provider:9091
consumer:8088
虚拟机地址: 192.168.111.135
修改配置application.yml文件:
将url地址替换为compose中对应的服务名:
spring:
datasource:
url: jdbc:mysql://mysql:3306/student?serverTimezone=UTC
defaultZone: http://eureka:10086/eureka
服务编排顺序:
mysql --> eureka->provider,consumer
分别编写每个微服务的DockerFile
FROM java:8
MAINTAINER ppt <1070196786@qq.com>
ADD provider.jar provider.jar
CMD ["java","-jar","provider.jar"]
编写docker-compose
version: "3.0"
services:
eureka:
build: ./eureka
ports:
- 10086:10086
depends_on:
- mysql
container_name: "eureka"
mysql:
image: mysql:5.7
container_name: "cloud_mysql"
ports:
- 3307:3306
volumes:
- /root/cloud/mysql/conf:/etc/mysql/conf.d
- /root/cloud/mysql/data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: root
provider:
build: ./provider
ports:
- 9091:9091
depends_on:
- mysql
- eureka
links:
- mysql
container_name: "provider"
consumer:
build: ./consumer
ports:
- 8088:8088
depends_on:
- eureka
container_name: "consumer"
目录结构:
把xxx.jar包和Docker分别放到每个文件夹下
运行命令:
docker-compose up -d
运行截图:
|