1.下载一个tomcat8,解压好改名为tomcat并配置端口为80,删除webapps下的默认的应用,修改tomcat/bin目录下脚本的权限,chmod +x *.sh

2.路径一般放在/usr/local目录下

2.编写Dockerfile如下:

FROM mcr.microsoft.com/java/jre:8u192-zulu-alpine

LABEL container="XX"

COPY tomcat /usr/local/tomcat

ENV TZ=Asia/Shanghai

ENV CATALINA_HOME=/usr/local/tomcat

ENV CATALINA_BASE=/usr/local/tomcat

ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/tomcat/lib:/usr/local/tomcat/bin

EXPOSE 80

CMD ["catalina.sh", "run"]





执行命令docker build -t tomcat:8-jre8-alpine .创建镜像

执行命令docker images|grep tomcat查看镜像

过程中遇到的问题:

解决办法:

代理服务器使用proxy

mkdir -p ~/proxy
cd ~/proxy
cat <<EOF >>startup.sh
#!/bin/sh

docker rm -f tinyproxy
docker run -d --name tinyproxy -p 8888:8888 dannydirect/tinyproxy:latest ANY
EOF
chmod +x startup.sh
./startup.sh

docker通过代理

这一步可以使服务器的docker命令通过代理(docker search、push、pull、login等)

 mkdir -p /etc/systemd/system/docker.service.d/

cat <<EOF > /etc/systemd/system/docker.service.d/http-proxy.conf

[Service]

Environment="HTTP_PROXY=http://172.19.20.100:8888" "NO_PROXY=registry-hz.fpi-inc.site"

EOF systemctl daemon-reload systemctl restart docker

 
02-12 15:50