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 to build a Tomcat running environment based on Docker

2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "how to build a Tomcat running environment based on Docker". In daily operation, I believe many people have doubts about how to build a Docker-based Tomcat operating environment. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to build a Docker-based Tomcat operating environment". Next, please follow the editor to study!

Environment

All the environments in this article, running ubuntu-13.10-server-amd64 on VMwareWorkStation, note that it is a 64-bit system, and other virtual machines are also feasible in theory.

Install Docker

Docker version 0. 7 requires linux kernel 3. 8 support, as well as an AUFS file system.

# check whether AUFS is installed

Sudo apt-get update

Sudo apt-get install linux-image-extra- `uname-r`

# add Docker repository key

Sudo sh-c "wget-qO- https://get.docker.io/gpg | apt-key add -"

# add Docker repository and install Docker

Sudo sh-c "echo deb http://get.docker.io/ubuntu docker main > / etc/apt/sources.list.d/docker.list"

Sudo apt-get update

Sudo apt-get install lxc-docker

# check whether Docker has been installed successfully

Sudo docker version

# Terminal output Client version: 0.7.1

Go version (client): go1.2

Git commit (client): 88df052

Server version: 0.7.1

Git commit (server): 88df052

Go version (server): go1.2

Last stable version: 0.7.1

Get rid of sudo

Under Ubuntu, when executing Docker, you have to enter sudo and password every time, which is very tiring. Fine-tune here to add the current user execution rights to the corresponding docker user group.

# add a new docker user group

Sudo groupadd docker

# add the current user to the docker user group, and note that the yongboy here is the ubuntu server login user name

Sudo gpasswd-a yongboy docker

# restart the Docker background monitoring process

Sudo service docker restart

# after reboot, try to see if it works

Docker version

# if the system restarts if it does not take effect, it will take effect

Sudo reboot

Install a Docker running instance-ubuntu virtual machine

After the Docker is installed, the background process starts automatically, and you can install the virtual machine instance (take the learn/tutorial image used in the official demonstration as an example):

Docker pull learn/tutorial

After the installation is complete, see how it works.

Docker run learn/tutorial / bin/echo hello world

Enter the newly installed virtual machine interactively

Docker run-I-t learn/tutorial / bin/bash

You will see:

Root@51774a81beb3:/#

Indicates that you have entered an interactive environment.

Install SSH terminal server so that we can log in and access it externally using SSH client.

Apt-get update

Apt-get install openssh-server

Which sshd

/ usr/sbin/sshd

Mkdir / var/run/sshd

Passwd # enter the user password. I set it to 123456 here to facilitate the login and use of the SSH client.

Exit # exit

Get the instance container ID you just operated

# docker ps-l

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

51774a81beb3 learn/tutorial:latest / bin/bash 3 minutes ago Exit 0 thirsty_pasteur

You can see that the container ID for the current operation is: 51774a81beb3. Note that once all operations are performed, you need to submit and save, so that SSH can log in and use:

Docker commit 51774a81beb3 learn/tutorial

Run this mirror instance as a background process for a long time:

Docker run-d-p 22-p 80 usr/sbin/sshd 8080 learn/tutorial / usr/sbin/sshd-D

The SSH Server running in the ubuntu container occupies port 22, which is specified by-p 22. -p 80 8080 means that our ubuntu will run tomcat on port 8080, but the port mapped to the outside (outside the container) is 80.

At this point, check to see if it runs successfully.

# docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

871769a4f5ea learn/tutorial:latest / usr/sbin/sshd-D About a minute ago Up About a minute 0.0.0.0 D About a minute ago Up About a minute 49154-> 22/tcp, 0.0.0.0 D About a minute ago Up About a minute 80-> 8080/tcp focused_poincare

Note that the port number of the random SSH connection assigned here is 49154:

Ssh root@127.0.0.1-p 49154

Enter the password, is it possible to enter? Once you have control of SSH, the rest is easy. Install JDK, install tomcat, etc., as you wish. The following is the installation script:

# install oracle jdk 7 on ubuntu 12.04

Apt-get install python-software-properties

Add-apt-repository ppa:webupd8team/java

Apt-get update

Apt-get install-y wget

Apt-get install oracle-java7-installer

Java-version

# download tomcat 7.0.47

Wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz

# decompress, run

Tar xvf apache-tomcat-7.0.47.tar.gz

Cd apache-tomcat-7.0.47

Bin/startup.sh

By default, port 8080 is occupied by tomcat. Just now, when starting the mirror instance, you specified-p 80purl 80dyubuntu mirror instance / container. If port 8080 is open, the port mapped to the host is 80. If you know the host IP address, you can access it freely. On the host, you can pass the curl test:

Curl http://192.168.190.131

Of course, you can also use a browser to access it.

In reality, tomcat may not be allowed to open port 80 directly to the public, but will usually be located behind the nginx/apache or firewall, which is only for demonstration.

At this point, the study on "how to build a Tomcat running environment based on Docker" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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