In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to make a JDK+tomcat image in docker. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Mode one
First of all, get the jdk and tomcat you want, and we need to create a Dockerfile file. What, you say you don't know what Dockerfile is and you can't write a Dockerfile file? Oh, that doesn't matter, you Ctrl+C will be fine. The complete contents of a Dockerfile file are shown below:
FROM ubuntu:14.10MAINTAINER linx# adds java and tomcat to the container ADD jdk-8u31-linux-x64.tar.gz / usr/local/ADD apache-tomcat-8.0.20.tar.gz / usr/local/# configuration java and tomcat environment variable ENV JAVA_HOME/ usr/local/jdk1.8.0_31ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jarENV CATALINA_HOME / usr/local/apache-tomcat-8.0.20ENV CATALINA _ BASE / usr/local/apache-tomcat-8.0.20ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin# container runtime listening port EXPOSE 8080
Of course, you still have to change a little bit, that is, the version of jdk and tomcat, and then the corresponding path after the version, ah, the rest can not be changed.
Then, jdk and tomcat need to be placed in the same path as this file.
Then, summon the terminal in the current path, enter
Docker build-t linx/tomcat
This command builds the image according to the rules of the Dockerfile file. When the monkey is finished, run gets up and starts tomcat with the following command
. / usr/local/apache-tomcat-8.0.20/bin/startup.sh
OK, visit port 8080 and you can see the familiar cat.
That's all. Let's start with a digression: the container opens port 8080, but you don't use 8080 to access the tomcat in the container. You know, the port of the container needs to be actively mapped to a port of the host. Forget it. Let me tell you a command to do port mapping:
# sudo docker run-d-p 5000Suzhou 8080 training/webapp
When starting a container, you can use the-p parameter to map port 8080 to port 5000 of the host, so that you can access port 5000 of the host to port 8080 of the container.
Also, in fact, the Dockerfile file helps you complete the setting of environment variables in the container, ah, and so on, in fact, you can do more and more powerful things, you must check the documents yourself!
Mode two
Although troublesome, still mention, after all, it is also a very normal way.
First of all, the next empty image of any system, and then run up and go in. In fact, what you are facing at this time is a host that has just been installed with a new system, so in fact, you understand again, start downloading the desired jdk and tomcat. Oh, it turns out that your host has already been downloaded. OK, here's how it works:
Docker run-I-t-v / root/software/:/mnt/software/ 25c5298b1a36 / bin/bash
Starting the container in the above way enables you to mount your software folder to the container's mnt/software/ directory, so when you enter the container, you will see the jdk and tomcat you want when you enter that folder.
All right, let's start decompressing and start setting environment variables. What, I don't know how to set environment variables in Linux? Then don't do it.
Vi ~ / .bashrc, enter vi editing mode and add the following configuration export JAVA_HOME=/opt/jdk/binexport PATH=$PATH:$JAVA_HOME at the end. Enter wq to exit the vi interface / / let the environment variables take effect source ~ / .bashrc
Above a short section of linux set environment variables method, for reference only, more ways and more powerful functions you have to check the documentation!
So, now that we've set up the environment variables for jdk and tomcat, right? Oh, let's move on to the next step. At this time, the environment variable has been set in the container. You can type Java-version to test whether it works or not. Then enter
Exit
Exit the container, where the container is paused, and then
Docker ps-a, listing all containers
When you see the container just exit, remember the container id, because we want to create a new image of ourselves based on the id, use the following command:
Docker commit 57c312bbaad1 myName/javaweb
Then we created an image called javaweb, in which we specified the jdk and tomcat.
This is the end of the article on "how to make a JDK+tomcat image in docker". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.