步骤:
一. 创建文件夹 xxx
二. 将资源放入文件夹xxx中
三. 编写Dockerfile文件

Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# CentOS with JDK 11
# Author mugua
# build a new image with basic centos
FROM centos:centos7.9.2009
# who is the author
MAINTAINER mugua
# copy the jdk archive to the image,and it will automaticlly unzip the tar file
ADD jdk-11.0.15.1_linux-x64_bin.rpm /root/
ADD ./kiftd /root/kiftd
ADD runkiftd.sh /root/runkiftd.sh
RUN yum localinstall /root/jdk-11.0.15.1_linux-x64_bin.rpm -y
RUN chmod +x /root/runkiftd.sh
CMD /root/runkiftd.sh
EXPOSE 8080

注意:

  1. FROM 代表基于那个系统,可以使用其它系统
  2. RUN 尽量用一行代码完成
  3. EXPOSE 代表使用端口,使用-p参数时,会随机映射一个端口到8080

runkiftd.sh

1
2
3
#!/bin/bash
nohup java -jar /root/kiftd/kiftd-1.1.0-RELEASE.jar -start & echo $!
/bin/bash

docker build

1
docker build -t="镜像名:版本" --no-cache .

注意:

  1. .不可少,代表当前目录
  2. –no-cache 代表不使用缓存
  3. 启动脚本xxx.sh,需要 #!bin/bash开头, /bin/bash结尾,否则无法运行Docker