使用docker-compose实现微服务编排部署
- 创建centos_jdk8镜像
Dockerfile命令如下:
--------------------------------------------
# 定义基础镜像
FROM centos:latest
# 定义维护者信息
MAINTAINER spdb
#添加宿主机的jdk 到容器中的指定目录
ADD jdk-8u111-linux-x64.tar.gz /usr/local
#设置环境变量
ENV JAVA_HOME=/usr/local/jdk1.8.0_111
ENV CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
ENV PATH=$PATH:$JAVA_HOME/bin
-----------------------------------------------
注释:新建一个文件夹centos_jdk1.8,然后把jdk-8u111-linux-x64.tar.gz发在文件夹内,创建Dockerfile文件,调用下面的启动命令,就可以创建镜像centos_jdk1.8了。
启动命令:
docker build -t centos_jdk8:latest . (这个. 不能省略)
图示如下:
- 创建docker-compose.yml文件
- 创建eureka的compose配置
- Dockerfile文件
Eureka的dockerfile配置文件,如下:
------------------------------------------------
#定义基础镜像
From centos_jdk8:latest
#添加eureka的jar到容器里对应的目录
ADD speed4j-eureka-server-0.0.1-SNAPSHOT.jar /eureka.jar
#ENTRYPOINT [“java”,”-Djava.security.egd=file:/dev/./urandom”,”-jar”,”/eureka.jar”]
- docker-compose.yml文件
-------------------------------------------------
version:’2’
services:
eureka-server:
image: eureka510:1.0
build:
context: ./eureka
dockerfile:Dockerfile
ports:
- “58881:1111”
container_name: eureka510
networks:
- net009
networks:
net009:
-------------------------------------------------
- 启动docker-compose命令:
docker-compose up -d
- 查看启动状态:
docker-compose ps
- 查看镜像:
docker image
- 查看访问效果:
虚拟机IP:映射外部端口
10.129.39.154:58881
- 关闭服务:
docker-compose down
- 查看日志信息:
docker-compose logs 服务名
或者 docker logs 容器id
-
- 创建eureka,config的compose文件
-------------------------------------------------
version:’2’
services:
eureka-server:
image: eureka509:1.0
build:
context: ./eureka
dockerfile:Dockerfile
ports:
- “58881:1111”
container_name: eureka509
networks:
- net009
config-server:
image: config509:1.0
build:
context: ./config
dockerfile: Dockerfile
ports:
- “58883:3333”
depends_on:
-eureka-server
volumes:
- /springboot/properties:/springboot/properties
container_name: config509
networks:
- net009
service:
image: service509:1.0
build:
context: ./service
dockerfile: Dockerfile
ports:
- “58882:2222”
- “58887:7001”
- “58899:7002”
container_name: service509
depends_on:
- eurekaserver
- configserver
networks:
- net009
restart: always
networks:
net009:
-------------------------------------------------
更多推荐
所有评论(0)