Docker builds Java Web Runtime environment

Source: Internet
Author: User

1. Pre-conditions
    • 64-bit Linux operating system with Docker installed
    • linux operating system image
    • linux version of JDK compression package
    • linux version of Tomcat compression package
2. start the container containers are run on the basis of mirroring, and once the container is started, we can log in to the container and install the software or application we need. Start command: (Docker Run < related parameters > < mirroring id> < initial command >) Docker run-i-t-v/root/software/:/mnt/software/25c5298b1a36/bin/bashamong them, the relevant parameters include:
    • -I: Indicates that the container is running in "interactive mode"
    • -T: Indicates that the container will enter its command line when it is started
    • -V: Indicates which directory needs to be mounted to the container, format:-v < host directory >:< container directory >
Assuming that all our installers are placed in the/root/software/directory of the host, it is now necessary to mount it to the container's /mnt/software/ directory. The initial command indicates the command to run once the container is started, using "/bin/bash" at this time to indicate nothing, just go to the command line. 3. install JDK and tomcat In order to build the Java WEB environment, we need to install the JDK and Tomcat, the following procedures are carried out inside the container. We may as well choose the/opt/directory as the installation directory, first through the cd/opt/command to enter the directory. 3.1. Installing the JDKFirst, unpack the JDK package:tar-zxf/mnt/software/jdk-8u101-linux-x64.gz-c.Then, rename the JDK directory:MV jdk1.8.101/jdk/3.2. Install TomcatFirst, unpack the Tomcat package:tar-zxf/mnt/software/apache-tomcat-9.0.0.m10.tar.gz-c.Then, rename the Tomcat directory:MV apache-tomcat-9.0.0.m10/tomcat/4. Setting environment variables First, edit the/etc/profile fileVi/etc/profilethen, add the following configuration at the end of the file:Export JAVA_HOME=/OPT/JDKexport path= $PATH: $JAVA _home/binFinally, you need to use the source command to make the environment variable effective:Source/etc/profile5. writing a run script we need to write a run script that, when the container is started, runs the script and launches Tomcat, as follows:First, create a run script:vi/root/run.shthen, edit the script content as follows:#!/bin/bashSource/etc/profilesh/opt/tomcat/bin/catalina.sh RunNote: You must load the environment variable first, and then use Tomcat's run script to start the Tomcat service. Finally, add execute permissions to run the script:chmod u+x/root/run.sh6. exit the container when all of the above steps are complete, you can use the Exit command to exit the container. you can then use the following command to view the container:Docker ps-a7. Create a Java Web image use the following command to create a new "mirror" based on a "container ID":Docker commit 57c312bbaad1 web_1.0The container's ID is "57c312bbaad1", the image name created is "web_1.0", and the Java Web container can then be started using mirroring. 8. Start the Java Web container first, use the Docker Images command to view all current mirrors:as described above, we can start the container with a "mirror name" or "Mirror ID", unlike the last time the container was started, we are now no longer entering the container's command line, but instead directly start the TOMCAT service inside the container. At this point, you need to use the following command:Docker run-d-P 8080:8080--name run_1.0 web_1.0/root/run.shA little explanation:
    • -D: The/root/run.sh script is executed in "daemon mode", at which point the Tomcat console does not appear on the output terminal.
    • -P: Represents the port mapping of the host to the container, at which point the 8080 port inside the container is mapped to the 8080 port of the host, exposing 8080 ports to the outside, and can access the 8080 ports inside the container via the Docker bridge.
    • --name: Represents the container name and is named with a meaningful name.
Finally, in the browser, enter the following address to access the Tomcat home page:http://hostip:8080/

Docker builds Java Web Runtime environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.