su
cd ~/
mkdir project-server (创建项目文件夹)
cd project-server/
rz (添加打包文件) 添加jdk1.8压缩包
vim Dockerfile(创建Dockerfile)
FROM docker.io/centos
MAINTAINER lixy
#将java添加到容器中
ADD jdk-8u172-linux-x64.tar.gz /usr/local/
ADD yumoq-cloud-project-server-1.0.0.jar /home/project-server.jar
#配置java与tomcat环境变量
ENV JAVA_HOME /usr/local/jdk1.8.0_172
ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
#ENV CATALINA_HOME /usr/local/apache-tomcat-7.0.86
#ENV CATALINA_BASE /usr/local/apache-tomcat-7.0.86
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin
EXPOSE 19310(映射的接口)
ENTRYPOINT ["nohup","java","-jar","/home/package-server.jar","--spring.profiles.active=peer0"](环境)
docker pull centos (拉取镜像)
docker build -t yumoq/project-server . (创建镜像)
cat readme 查看运行容器命令
docker images(查看镜像)
docker run --name package-server -d -p 19010:19010 -e TZ="Asia/Shanghai" --restart=always yumoq/package-server (运行容器)
docker logs --tail 1000 project-server -f (容器日志查看命令)
(创建自启文件)
find / -name project-server.jar
vim restart.sh
cat restart.sh (自启文件内容)
sudo cp ./yumoq-cloud-package-server-1.0.0.jar /var/lib/docker/overlay2/c9ddec2a115ca5f8245835e477dd737dae3c60ce961bc8b11d2fb000817693f1/diff/home/package-server.jar
sudo cp ./yumoq-cloud-package-server-1.0.0.jar /var/lib/docker/overlay2/c4be3897264eb6ed29de6a258d81acad252c5015dd1fe7e1a0c5818b39f165ac/diff/home/package-server.jar
sudo cp ./yumoq-cloud-package-server-1.0.0.jar /var/lib/docker/overlay2/c9ddec2a115ca5f8245835e477dd737dae3c60ce961bc8b11d2fb000817693f1/merged/home/package-server.jar
docker stop 22726efe96da(容器ID)
docker start 22726efe96da
sh restart.sh (重启)