Docker deployment Tomcat

Source: Internet
Author: User
Tags docker ps docker hub docker run

I. Environmental profile

Host version: Ubuntu-14.04.3-server-amd64.iso

JDK version: jdk-7u76-linux-x64.tar.gz

Tomcat version: Apache-tomcat-7.0.52.zip

Two. The Ubuntu 14.04 version of the system has its own Docker, view the next Docker version

Docker version

Third, (optional) SSH login server-side preparation

Use the SSH client tool to log in, specifically refer to http://jingyan.baidu.com/article/9c69d48fb9fd7b13c8024e6b.html installation OpenSSH
sudo apt-get updatesudoinstall openssh-server
Iv. Download Container image

Get mirrored to Local

sudo Docker pull bobsha/ping

Here Bobsha is my Docker hub username bobsha/ping is the Ubuntu image I uploaded to a ping command.

Of course, you can also apply for an account for management, the URL is https://hub.docker.com

View local image information

sudo docker images

Five, host and target container mount directory preparation

This step is to install the installation software that the Docker container needs to use and the Tomcat-run project to be ready on the host and mounted in the container.

First, the software is ready to be placed under the host/opt/software, in the container/mnt add software directory below.

Build/opt/webapps/root in the host/opt and add the index.html file, adding the following:

Six, container tomcat running environment preparation

Docker Run-i-t-v/opt/software/:/mnt/software/8ab8/bin/bashThe command consists of the following three sections:Docker Run < related parameters > < mirroring id> < initial commands >among 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 >

The above steps now go into the container's interactive window, extract the Tomcat and JDK into the/opt directory, and write the Tomcat startup script.

Build the runtomcat.sh file below/opt and add the following:

#!/bin/bashexport java_home=/opt/jdk1. 7. 0_76/export PATH= $JAVA _home/bin: $PATHsh /opt/apache-tomcat-7.0 . /bin/catalina. SH Run

assigning Permissions to Scripts

chmod U+x/opt/runtomcat. SH

Exit container

Exit

View recently run container information

PS -L

[Email protected]:/opt/software# Docker ps-l

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
23D53A7745BC bobsha/ping:latest "/bin/bash" about a minute ago Exited (0) seconds ago Backstabbing_lumiere

Save the container as a new image, I'll name the new image Bobsha/tomcat

Docker commit 23d5 bobsha/Tomcat

Here the container ID only need to write the first few can distinguish the line general, three to four bits can.

Vii. running Tomcat

Run Tomcat, this time just run launch tomcat command Docker run-p 18080:8080-v/opt/webapps/:/opt/apache-tomcat-7.0.52/webapps/-name docker_ Tomcat bobsha/tomcat/opt/runtomcat.shamong these, the newly arisen parameters include:
    • -p:< host Port >:< container port, map container port to specified host port, Access container program via host port

    • -name: Name of the container, a meaningful name can be

Verifying Tomcat Performance

Through the LAN browser access: http://192.168.0.106:18080/index.html Display success! Eight, remove the container Ctrl + C exit, found to run the above command is displayed as follows: Warning: '-name ' is deprecated, it'll be a replaced by '--name ' soon. See usage. FATA[0000] Error response from Daemon:conflict. The name "Docker_tomcat" is already on use by container BAB14EF39B40. You had to delete (or rename) that container to be able to reuse that name. View all containers
PS -A

container id        IMAGE                   command                 created              status                        ports                      NAMES

BAB14EF39B40 bobsha/tomcat:latest "/opt/runtomcat.sh" Ten minutes ago Exited (8 minutes ago) Docker_tomcat Removing the container
RM BAB1
This article refers to the following articles and tutorials: http://www.docker.org.cn/book/docker.htmlhttp://m.oschina.net/blog/616526?hmsr=toutiao.io&utm_ Medium=toutiao.io&utm_source=toutiao.io

Docker deployment Tomcat

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.