我要评分
获取效率
正确性
完整性
易理解

Using a Self-Built Image for Deployment

This section uses TomEE-8.0.1-plus as an example.

  1. Create a tomee_dockerfile directory and go to the directory.
    1
    mkdir tomee_dockerfile
    
    1
    cd tomee_dockerfile
    
  2. Download the TomEE installation package.
    1
    wget https://archive.apache.org/dist/tomee/tomee-8.0.1/apache-tomee-8.0.1-plus.tar.gz --no-check-certificate
    
  3. Prepare the Dockerfile file in the tomee_dockerfile directory.
    1. Create and open the Dockerfile file.
      1
      vim Dockerfile
      
    2. Edit the Dockerfile file as follows:
      FROM openjdk:11-jre
      
      ENV PATH /usr/local/tomee/bin:$PATH
      RUN mkdir -p /usr/local/tomee
      
      WORKDIR /usr/local/tomee
      
      COPY apache-tomee-8.0.1-plus.tar.gz /usr/local/tomee
      
      ENV TOMEE_VER 8.0.1
      ENV TOMEE_BUILD plus
      
      RUN set -x \
      	&& tar -zxf apache-tomee-8.0.1-plus.tar.gz \
      	&& mv apache-tomee-${TOMEE_BUILD}-${TOMEE_VER}/* /usr/local/tomee \
      	&& rm -Rf apache-tomee-${TOMEE_BUILD}-${TOMEE_VER} \
      	&& rm bin/*.bat \
      	&& rm apache-tomee-8.0.1-plus.tar.gz*
      #	&& useradd -g root tomee \
      #	&& chown -R tomee:root /usr/local/tomee \
      #	&& chmod -R g=u /usr/local/tomee
      
      #USER tomee
      EXPOSE 8080
      CMD ["catalina.sh", "run"]
    3. Press Esc and enter :wq to save the file and exit.
  4. Check the files in the tomee_dockerfile directory.
    ls

  5. Build an installation image.
    1. Build an image.
      Based on the Dockerfile file in the current directory, build an image named arm/test/tomee with the tag 11-jre-8.0.1-plus.
      1
      docker build -t arm/test/tomee:11-jre-8.0.1-plus .
      

      If the following information is displayed, the installation image is successfully built:

      Successfully built xxxxxxxx
      Successfully tagged arm/test/tomee:11-jre-8.0.1-plus

      Do not omit the dot (.) at the end of the docker build -t arm/test/tomee:11-jre-8.0.1-plus . command. Otherwise, an error may occur during the execution of the command.

    2. View the image.
      1
      docker images
      

  6. Run a container instance by using the image.
    1. Create a container and run it in the background.

      Create a container named arm-test-tomee and map port 8080 in the container to port 9999 on the host machine. The container runs in daemon mode.

      1
      docker run -itd -p 9999:8080 --name arm-test-tomee arm/test/tomee:11-jre-8.0.1-plus
      

    2. View the running container.
      1
      docker ps
      

  7. Verify the running of TomEE.

    Open a browser and enter http://host IP:9999 in the address box to access port 9999 of the Docker host machine. If the home page of the TomEE service is displayed, the TomEE service is successfully deployed and running on the Docker.

  1. If port 9999 is occupied, you can use another port.
  2. In the official image, the installation directory of TomEE is /usr/local/tomee/, the configuration file is located in the /usr/local/tomee/conf/ directory, and the web application (WAR files) can be deployed in the /usr/local/tomee/webapps directory.