Build the java web environment using Dockerfile
- 2020-05-30 21:22:31
- OfStack
Building an web environment for Java with dockerfile is divided into two steps. The first step is to install jdk in the image and configure the environment variables. The second step is to install tomcat.
First post the full dockerfile
FROM ubuntu:14.04
MAINTAINER *** "***@******.com"
RUN apt-get update
ADD jdk-8u77-linux-x64.tar.gz /usr/local/java
ENV JAVA_HOME /usr/local/java/jdk1.8.0_77
ENV PATH $JAVA_HOME/bin:$PATH
ENV CLASSPATH .:$JAVA_HOME/lib
COPY apache-tomcat-8.0.33/ /usr/local/tomcat/apache-tomcat-8.0.33/
#RUN unzip /usr/local/tomcat/apache-tomcat-8.0.33.zip
RUN chmod +x /usr/local/tomcat/apache-tomcat-8.0.33/bin/*.sh
EXPOSE 8080
ENTRYPOINT /usr/local/tomcat/apache-tomcat-8.0.33/bin/startup.sh && /bin/bash
The original image is ubuntu14.04, then put the installation packages for jdk and tomcat in the same directory as dockerfile.
This Dockerfile is relatively simple, jdk and tomcat do not need to be compiled, are decompressed and ready to use, so there is nothing special about it.
When Dockerfile is finished, build the image in the same folder as Dockerfile
docker build -t="redstarofsleep/javaweb" .
Finally, run the image. Remember to bind the port when you run the image
docker run -d -t -i -p 8081:8080 redstarofsleep/javaweb