Dockerfile deployment java web environment details
- 2020-05-30 21:22:27
- OfStack
Dockerfile builds the java web environment
Dockfile is introduced:
Dockfile is a script interpreted by the Docker program. Dockerfile consists of 1 instruction and 1 instruction, and each instruction corresponds to the following command of Linux. The Docker program translates these Dockerfile instructions into actual Linux commands. While Dockerfile has its own written format and supported commands, the Docker program resolves dependencies between these commands, similar to Makefile. The Docker program will read Dockerfile and generate a custom image based on the instruction. An obvious script like Dockerfile is more acceptable to the user than a black box like image, which clearly shows how image was created. With Dockerfile, when we need to customize our additional requirements, we only need to add or modify the instruction on Dockerfile and regenerate image, which saves the trouble of typing the command.
Building an Java web environment with dockerfile is divided into 2 steps.
Step 1 is to install jdk in the image and configure the environment variables,
Step 2 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.
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
Thank you for reading, I hope to help you, thank you for your support of this site!