Docker部署jar

1 环境

  • Ubuntu18.04
  • Java8

2 查询Java8Docker镜像

sudo docker search java8

3 拉取Java8镜像

  • 拉取
sudo docker pull williamyeh/java8
  • 完成拉取
Using default tag: latest
latest: Pulling from williamyeh/java8
f2b6b4884fc8: Pull complete 
c6c308a14d13: Pull complete 
Digest: sha256:174d528516a0eae5c4df69966eeb5e51d7c0dc1a532249af61013953eab1d9f3
Status: Downloaded newer image for williamyeh/java8:latest
  • 查看镜像
sudo docker image ls
  • 镜像列表
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
appbaseio/dejavu         latest              94d9f7a08f50        9 months ago        135MB
hello-world              latest              fce289e99eb9        16 months ago       1.84kB
williamyeh/java8         latest              00bc163fa009        2 years ago         593MB
containerize/elastichd   latest              c2202f76db37        2 years ago         28.1MB
  • 镜像保存位置
/var/lib/docker

4 新建jar包路径

mkdir -p /home/xdq/xinPrj/java/docker-jar

jar包拷贝到docker-jar文件夹中.

5 新建Dockerfile

  • 新建
# 进入docker-jar文件夹
cd /home/xdq/xinPrj/java/docker-jar
# 新建Docker配置文件
touch Dockerfile
  • 文件内容
# 环境
FROM williamyeh/java8:latest
# 管理者信息
MAINTAINER xindaqi "[email protected]"
# 本地文件挂载到容器
WORKDIR /home/xdq/xinPrj/java/docker-jar
# 拷贝jar文件
COPY base-framework.jar /base-framework.jar
# 设置端口号
EXPOSE 8090
# 运行jar包
ENTRYPOINT ["java", "-jar", "/base-framework.jar", "&"]

6 新建后台运行镜像

  • 新建镜像
sudo docker build -t base-framework:1.0 /home/xdq/xinPrj/java/docker-jar
  • 提示信息
Sending build context to Docker daemon  42.38MB
Step 1/6 : FROM williamyeh/java8:latest
 ---> 00bc163fa009
Step 2/6 : MAINTAINER xindaqi "[email protected]"
 ---> Running in 35d8d45b8600
Removing intermediate container 35d8d45b8600
 ---> 6090e383a683
Step 3/6 : WORKDIR /home/xdq/xinPrj/java/docker-jar
Removing intermediate container b65b17b8321b
 ---> 3067fd72d3f1
Step 4/6 : COPY base-framework.jar /base-framework.jar
 ---> 105d4b84910b
Step 5/6 : EXPOSE 8090
 ---> Running in 69e103d928ec
Removing intermediate container 69e103d928ec
 ---> 92cca32d975c
Step 6/6 : ENTRYPOINT ["java", "-jar", "/base-framework.jar", "&"]
 ---> Running in 4de0f45454fc
Removing intermediate container 4de0f45454fc
 ---> 5abc03a36696
Successfully built 5abc03a36696
Successfully tagged base-framework:1.0

  • 镜像列表
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
base-framework           1.0                 5abc03a36696        4 minutes ago       636MB
appbaseio/dejavu         latest              94d9f7a08f50        9 months ago        135MB
hello-world              latest              fce289e99eb9        16 months ago       1.84kB
williamyeh/java8         latest              00bc163fa009        2 years ago         593MB
containerize/elastichd   latest              c2202f76db37        2 years ago         28.1MB

7 运行镜像

sudo docker run -d -p8090:8090 base-framework:1.0

8 查看镜像运行信息

  • 查看镜像
sudo docker ps -l
  • 未运行镜像
CONTAINER ID        IMAGE                 COMMAND                   CREATED             STATUS                       PORTS                    NAMES
  • 运行中镜像
CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                    NAMES
b5c9ffe8b93b        base-framework:1.0   "java -jar /base-fra…"   13 seconds ago      Up 10 seconds       0.0.0.0:8090->8090/tcp   inspiring_allen

9 删除镜像

  • 删除容器
sudo docker rm b5c9ffe8b93b
  • 删除镜像
sudo docker rmi base-framework:1.0

【参考文献】
[1]https://blog.csdn.net/qq_40673786/article/details/100621924
[2]http://www.6tie.net/p/995433.html
[3]https://blog.csdn.net/Xin_101/article/details/89208620

你可能感兴趣的:(#,Docker,Docker,Jar)