English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Content
This article will explain how to make the Javaweb project in the previous article into a Docker image. The editor thinks it's quite good and now shares it with everyone for reference. Let's follow the editor to take a look together
The steps are very clear, but to create a Docker image, you still need another thing: Dockerfile.
Dockerfile is a file containing special instructions that Docker can recognize. After creating the Dockerfile file, you can use docker build to create the docker image.
Start building the Docker image
The structure is as shown below:
Build the structure diagram of Docker image
Create image
docker build -t "zsl131/web01" .
Note:
docker build: Create Docker image
-t "zsl131/web01": Specify the image name, here specify it as zsl131/web01; the image name consists of two parts: repository and name, zsl131is the repository name I registered and applied for on hub.docker.com, web01is the name of this image
.: Note that there is a space in front, indicating that the Dockerfile file in the current directory is used to build the image.
The following is the Dockerfile for creating the Docker image in this example, in order to better understand Dockerfile, you can delete all the instructions in the following file, and then execute once for each added line: docker build -t "zsl131/web01" ., so you can see various information when building the image with Dockerfile:
# Based on Centos7as the base image FROM centos:7 # When you don't know how to install JDK, you can enable the following command and then run: docker build #RUN yum search java | grep jdk # Choose the appropriate JDK version to install RUN yum install -y java-1.7.0-openjdk.x86_64 # Create a directory named web under the root directory RUN mkdir /web/ # Set the working directory to/web, after setting it, you can use: RUN pwd to view the current path WORKDIR /web/ # Install wget to facilitate the download of Tomcat RUN yum install -y wget # Download the Tomcat compressed file RUN wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-6/v6.0.48/bin/apache-tomcat-6.0.48.tar.gz # Unzip the Tomcat files RUN tar zxvf apache-tomcat-6.0.48.tar.gz # Set the tool directory WORKDIR /web/apache-tomcat-6.0.48/webapps/ROOT/ # List all files (folders) in the current directory, at this time there will be some files from Tomcat itself RUN ls -l # Delete all files (folders) in the current directory RUN rm -rf * # After deleting, list again, at this time there are no files RUN ls -l # Copy all files (folders) under the WebRoot directory to the current directory (webapps/ROOT), here you can also use the COPY command ADD WebRoot . # After copying, you can list to see if the copy was successful RUN ls -l # Set the working directory to the Tomcat bin directory to facilitate the start of the Tomcat service WORKDIR /web/apache-tomcat-6.0.48/bin/ # Expose Tomcat to the outside8080 port EXPOSE 8080 # Start the Tomcat service, so that it will not be overwritten when running docker run ENTRYPOINT ["./"catalina.sh", "run"]
After completing the writing of Dockerfile, finally build the image through the following command:
docker build -t "zsl131/web01" .
You can view the image just built by using the command docker images.
Run container
docker run -d --name web01 -p 80:8080 zsl131/web01
Description:
docker run: run container command
-d: run in the background
--name web01Set the container name to web01
-p 80:8080: specify the exposed port as80, that is, when externally accessed80 port will be mapped to the container inside8080 port
zsl131/web01The name of the image
View container startup logs
docker logs web01
Description:
docker logs: the command to view container logs
web01The name of the container to be viewed, here is web01
Access
Open the browser and enter: http://192.168.99.100 to access the Javaweb project created by MyEclipse.
Note:192.168.99.100 is the IP address of my Docker host. It can be accessed through docker-machine inspect test01To view, among which test01Is the name of the Docker host.
That's all for this article. I hope it will be helpful to your studies, and I also hope everyone will support the Yelling Tutorial more.
Statement: The content of this article is from the Internet, and the copyright belongs to the original author. The content is contributed and uploaded by Internet users spontaneously. This website does not own the copyright, does not edit the content manually, and does not assume any relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (when sending an email, please replace # with @ to report, and provide relevant evidence. Once verified, this site will immediately delete the infringing content.)