Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How Docker automatically deploys Apache Tomcat

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "Docker how to automatically deploy Apache Tomcat", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Docker how to automatically deploy Apache Tomcat" this article.

Apache Tomcat

Use docker search to find the most popular (and official) Docker Tomcat containers:

$sudo docker search tomcat [sudo] password for craig: NAME DESCRIPTION STARS OFFICIAL AUTOMATEDtomcat Apache Tomcat is an open source implementa... 103 [OK] tutum/tomcat Tomcat image-listens in port 8080. For t... 38 [OK] consol/tomcat-7.0 Tomcat 7.0.57, 8080, "admin/admin" 12 [OK] consol/tomcat-8.0 Tomcat 8.0.15, 8080, "admin/admin" 9 [OK] consol/tomcat-6.0 Tomcat 6.0.43, 8080 "admin/admin" 6 [OK] consol/tomcat-4.1 Tomcat 4.1.40, 8080, "admin/admin" 4 [OK] consol/tomcat-5.0 Tomcat 5.0.30, 8080, "admin/admin" 4 [OK] consol/tomcat-5.5 Tomcat 5.5.36, 8080 "admin/admin" 4 [OK] consol/tomcat-3.3 Tomcat 3.3.2, 8080, "admin/admin" 4 [OK] readytalk/tomcat-native Debian backed Tomcat + Tomcat Native Library 3 [OK] malderhout/tomcat Tomcat7 with OpenJDK7 on CentOS7 3 [OK] dordoka/tomcat Ubuntu 14.04, Oracle JDK 8 and Tomcat 8 ba... 3 [OK] meirwa/spring-boot-tomcat-mysql-app a sample spring-boot app using tomcat and... 2 [OK] h3000/docker-tomcat-youtrack Dockerfile for youtrack to run under tomcat. 1 [OK] nicescale/tomcat Tomcat service for NiceScale. Http://nices... 1 [OK] dmean/liferay-tomcat Debian + Liferay CE Tomcat 1 [OK] atomi/tomcat 0 [OK] mminke/apache-tomcat A Docker image which contains the Apache T... 0 [OK] ericogr/tomcat Tomcat 8.0.21, 8080 "docker/docker" 0 [OK] holmes/tomcat 0 [OK] paulkling/tomcat 0 [OK] dynamind/tomcat 0 [OK] fabric8/tomcat-8.0 runs Apache Tomcat 8.0 with jolokia enable... 0 [OK] learninglayers/tomcat 0 [OK] dmglab/tomcat CentOS 7 based tomcat installation 0 [OK]

The official website describes the supported tags:

I'm using version 7, so I chose tomcat:7.

I am new to using Docker (when writing this article), so I don't want to call this article a "best practice". What is written in this article is the practice that I think is good to use. Please let me know if you have any different opinions. For each Docker container I want to start, I create my own Dockerfile and extend the image. Of course, it is completely possible to use the image without expanding it. But building our own images based on target images should be a more appropriate way to steadily expand the work of others.

In the example in this article, a simple Dockerfile is created, as follows:

FROM tomcat:7-jre7MAINTAINER "Craig Trim"

Build the image with the following command:

$sudo docker build-t craig/tomcat.

One benefit of this expansion is that it simplifies the environment. Eventually, I'm going to use containers for Eclipse, MySQL, and other applications. I will give each application a simplified namespace and image name. When working on a project, I recommend using the code name of the project as the container namespace. I also simplified the tag name. These are very small notes, but they are very important. In large projects, there are many developers involved, and this approach can be very helpful. A common namespace and simplified image names and tags will make it easier for project members to use the official project image.

My example is as follows:

Tomcat:7-jre7 ns/tomcatmysql:5.6.23 ns/mysqlfgrehm/eclipse:v4.4.1 ns/eclipse

Ns stands for namespaces, which every project member can understand. You only need to remember the project code name (namespace) and the application name to start the container.

Run Tomcat

The following command runs Tomcat and exposes port 8080 of the container to port 8080 of the host machine:

$sudo docker run-p 8080 8080 craig/tomcat

If you also need to start the container from this image, just:

$sudo docker run-p 8081 8080 craig/tomcat

The test tomcat has been started:

Extended Dockerfile

I need to extend Dockerfile to automate the deployment of Maven. You need to add settings.xml and update the tomcat-user.xml file. As follows:

Tomcat-users.xml:

Settings.xml:

TomcatServercraigpassword

These files are placed in the same directory as Dockerfile.

The Dockerfile is updated to:

FROM tomcat:7-jre7MAINTAINER "Craig Trim" ADD settings.xml / usr/local/tomcat/conf/ADD tomcat-users.xml / usr/local/tomcat/conf/

When the image is built, the configuration file is placed in the correct directory. Any container launched from this image will contain these files.

Reconstruct the image

Rebuild the image using the previous method:

$sudo docker build-t craig/tomcat .Sending build context to Docker daemon 5.632 kBSending build context to Docker daemon Step 0: FROM tomcat:7-jre7--- > 77eb038c09d1Step 1: MAINTAINER "Craig Trim"-> Using cache--- > cadc51a3054cStep 2: ADD settings.xml / usr/local/tomcat/conf/--- > Using cache--- > 5009ba884f1fStep 3: ADD tomcat-users.xml / usr/local/tomcat/conf/--- > Using cache--- > 33917c541bb5Successfully built 33917c541bb5

You can view the image history:

$sudo docker history craig/tomcatIMAGE CREATED CREATED BY SIZE33917c541bb5 4 hours ago / bin/sh-c # (nop) ADD file:c1d08c42d5808537b4 1.761 kB5009ba884f1f 4 hours ago / bin/sh-c # (nop) ADD file:5dd8f0f6d0cd64de3c 212 Bcadc51a3054c 4 hours ago / bin/sh-c # (nop) MAINTAINER "Craig Trim

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report