环境
docker:Docker version 17.11.0-ce
ubuntu: 14.04
java: 8
tomcat: 7
docker化,并上传至harbor
Dockerfile
FROM ubuntu:14.04 MAINTAINER xiaojie ADD jdk-8u71-linux-x64.tar.gz /usr/local/ ADD apache-tomcat-7.0.70.tar.gz /usr/local/ ADD tomcat-users.xml /usr/local/apache-tomcat-7.0.70/conf/ ADD settings.xml /usr/local/apache-tomcat-7.0.70/conf/ ADD demo.war /usr/local/apache-tomcat-7.0.70/webapps/ ENV JAVA_HOME /usr/local/jdk1.8.0_71 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-7.0.70 ENV CATALINA_BASE /usr/local/apache-tomcat-7.0.70 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin EXPOSE 8080 ENTRYPOINT ["/usr/local/apache-tomcat-7.0.70/bin/catalina.sh", "run" ]
tomcat-users.xml
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="demo" password="demo11111" roles="manager-gui,manager-script"/>
</tomcat-users>
- settings.xml
<?xml version="1.0"encoding="UTF-8"?>
<settings>
<servers>
<server>
<id>TomcatServer</id>
<username>demo</username>
<password> demo11111</password>
</server>
</servers>
</settings>
build, run
docker stop demo-container docker rm demo-container docker build -t demo/tomcat . docker run --name demo-container -d -p 8080:8080 demo/tomcat
push之前需要将harbor地址加入到信任中,vi /etc/default/docker
DOCKER_OPTS=”$DOCKER_OPTS –insecure-registry ...:8888″
push至私有harbor库
docker login -u demo -p password123 **.**.**.**:8888 docker tag demo/tomcat **.**.**.**:8888/demo/tomcat docker push **.**.**.**:8888/demo/tomcat
坑点
- 保持tomcat版本、java版本和开发环境一样,不然可能会有莫名的问题