Dockerfile 部署Java tomcat
1. Dockerfile文件
FROM centos:7 MAINTAINER ADD jdk-8u181-linux-x64.tar.gz /usr/local ENV JAVA_HOME /usr/local/jdk1.8.0_181 ADD http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz /usr/local RUN tar -xvf /usr/local/apache-tomcat-8.5.50.tar.gz -C /usr/local/ ENTRYPOINT ["/usr/local/apache-tomcat-8.5.50/bin/catalina.sh", "run"] EXPOSE 8080
遇到一个问题,ADD http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.50/bin/apache-tomcat-8.5.50.tar.gz /usr/local
该命令没有自动解压apache-tomcat-8.5.50.tar.gz,所以后面加了一个RUN命令来专门解压:
RUN tar -xvf /usr/local/apache-tomcat-8.5.50.tar.gz -C /usr/local/
jdk-8u181-linux-x64.tar.gz 在当前目录下面。
2. build
docker build -t tomcat:v1 -f ./Dockerfile-java .
根据 Dockerfile-java 文件来build tomcat:v1
3. run
docker run -itd --name tomcat -p 8989:8080 tomcat:v1
把build的镜像run起来:
4. 测试:
可以访问。
5. 部署sshd
Dockerfile内容:
FROM centos:7
MAINTAINER
ENV ROOT_PASSWORD 123456
RUN yum install -y openssh-server
RUN echo $ROOT_PASSWORD |passwd --stdin root
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
CMD ["/usr/sbin/sshd", "-D"]
EXPOSE 22
启动:
测试登陆: