将上一步的jar包拷贝到Linux服务器,准备创建镜像。 测试jar包是否可以运行,执行:java -jar xc-govern-center-1.0-SNAPSHOT.jar
在xc-govern-center-1.0-SNAPSHOT.jar 位置编写Dockerfile文件
[AppleScript] 纯文本查看 复制代码 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 ENTRYPOINT ["java", "‐jar", "xc‐govern‐center.jar"]
在Dockerfile文件所在目录执行:docker build -t xc-govern-center:1.0-SNAPSHOT .
镜像创建成功,查询镜像:
[AppleScript] 纯文本查看 复制代码 [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
3.2.5 创建容器
基于xc-govern-center:1.0-SNAPSHOT镜像创建容器,容器名称为xc-govern-center-test
[AppleScript] 纯文本查看 复制代码 docker create ‐‐name xc‐govern‐center‐test ‐t ‐p 50101:50101 ‐e PORT=50101 ‐e EUREKA_SERVER=http://192.168.101.64:50101/eureka/,[url]http://192.168.101.64:50102/eureka/[/url] xcgovern‐center:1.0‐SNAPSHOT
容器创建成功,可通过docker ps -a命令查看 3.2.6 启动容器
docker start xc-govern-center-test 容器启动完成可以通过docker ps 查询正在运行中的容器。
[AppleScript] 纯文本查看 复制代码 [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
|