将上一步的jar包拷贝到Linux服务器,准备创建镜像。 测试jar包是否可以运行,执行:java -jar xc-govern-center-1.0-SNAPSHOT.jar 在xc-govern-center-1.0-SNAPSHOT.jar 位置编写Dockerfile文件 [mw_shl_code=applescript,true]FROM java:8 ENV ARTIFACTID xc‐govern‐center ENV ARTIFACTVERSION 1.0‐SNAPSHOT ENV HOME_PATH /home WORKDIR $HOME_PATH ADD /$ARTIFACTID‐$ARTIFACTVERSION.jar $HOME_PATH/$ARTIFACTID.jar EYPOINT ["java", "‐jar", "xc‐govern‐center.jar"][/mw_shl_code] 在Dockerfile文件所在目录执行:docker build -t xc-govern-center:1.0-SNAPSHOT . 镜像创建成功,查询镜像:

[mw_shl_code=applescript,true][root@localhost xc‐govern‐center]# docker images REPOSITORY
TAG
IMAGE ID
CREATED
SIZE xc‐govern‐center
1.0‐SNAPSHOT
ad14dcce6666
35 seconds ago
684 MB[/mw_shl_code] 3.2.5 创建容器 基于xc-govern-center:1.0-SNAPSHOT镜像创建容器,容器名称为xc-govern-center-test

[mw_shl_code=applescript,true]docker create ‐‐name xc‐govern‐center‐test ‐t ‐p 50101:50101 ‐e PORT=50101 ‐e EUREKA_SERVER=http://192.168.101.64:50101/eureka/,http://192.168.101.64:50102/eureka/ xcgovern‐center:1.0‐SNAPSHOT [/mw_shl_code] 容器创建成功,可通过docker ps -a命令查看 3.2.6 启动容器 docker start xc-govern-center-test 容器启动完成可以通过docker ps 查询正在运行中的容器。

[mw_shl_code=applescript,true][root@localhost xc‐govern‐center]# docker ps CONTAINER ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES 688cabeef187
xc‐govern‐center:1.0‐SNAPSHOT "java ‐jar xc‐gove..." 2 minutes ago
Up 2 minutes
0.0.0.0:50101‐>50101/tcp
xc‐govern‐centertest [/mw_shl_code]