Docker one of the learning notes to build a Java Tomcat runtime environment

Source: Internet
Author: User
Tags curl ssh access ssh server docker ps docker run
In -situ: http://www.blogjava.net/yongboy/archive/2013/12/12/407498.html Preface

Docker is designed to provide an automated deployment solution for applications, quickly creating a container (lightweight virtual machine) on a Linux system and deploying and running applications, and making it easy to automate installation, deployment, and upgrades of applications through configuration files. Because the use of containers, so can be very convenient to the production environment and development environment separate, not affect each other, this is the most common one of the Docker play. More games include large-scale Web applications, database deployments, ongoing deployments, clustering, test environments, service-oriented cloud computing, virtual desktop VDI, and more.

Subjective impression: Docker use go language to write, use Cgroup to achieve resource isolation, container technology using LXC. Provides a lightweight virtualization solution that can run UNIX processes independently. It provides a way to automate the deployment of software in a secure, repeatable environment. LXC command is somewhat complicated, if interested, here is an article I previously wrote based on Lxc, (from scratch, to build a simple version of the Java PAAs Cloud platform), you can review it in advance.

The principle of implementation, the relevant theory, the use of scenes, etc., will be written in the back of this series, here first a taste, completely manual, based on Docker to build a tomcat operating environment. First out of a good demo, you can see the effect, may let us go a little farther. Environment

All environments in this article, VMware Workstation running UBUNTU-13.10-SERVER-AMD64, note that the 64-bit system, in theory, other virtual machines are completely feasible. Install Docker

The Docker 0.7 version requires Linux kernel 3.8 support and requires a Aufs file system.

# Check to see if 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 if Docker is 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< C16/>last Stable version:0.7.1
to get rid of sudo.

In Ubuntu, in the implementation of Docker, each time to enter sudo, and enter the password, very tiring, here fine-tuning, the current user to execute the right to add to the corresponding Docker user group.

# Add a new Docker user group
sudo groupadd Docker
# Add current user to Docker user group, note here yongboy for Ubuntu Server login username
sudo Gpasswd-a yongboy Docker
# reboot Docker background monitoring process
sudo service docker restart
# after the reboot, try it and see if it takes effect
Docker Version
#若还未生效, the system reboots, and the
sudo reboot
Install a Docker run instance-ubuntu virtual machine

Docker installation completed, background process also automatically started, you can install the virtual machine instance (here directly with the official demo of the use of the learn/tutorial image as an example):

Docker Pull Learn/tutorial

After the installation is complete, look at the effect

Docker Run Learn/tutorial/bin/echo Hello World

Interactive access to newly installed virtual machines

Docker Run-i-T Learn/tutorial/bin/bash

will see:

The description has entered an interactive environment.

Install the SSH Terminal Server to facilitate our external access using SSH client

Apt-get Update
apt-get install Openssh-server
which
sshd/usr/sbin/sshd mkdir/var/run/sshd passwd #输入用户密码, I set it to 123456 to facilitate SSH client login to use
exit #退出

Gets the instance container ID that was just manipulated

#docker ps-l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 51774a81beb3 Learn/tutorial:latest/bin/bas
H 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 have been made, they need to be submitted for storage for SSH access:

Docker commit 51774A81BEB3 Learn/tutorial

This mirror instance will run for a long period of time in the next session:

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

The SSH server is running in the Ubuntu container , the port is occupied, and-P 22 is specified. - P 80:8080 refers to us that Ubuntu will run Tomcat on 8080 ports, but the outbound (out of container) map port is 80.

Now, 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:49154->22/tcp, 0.0.0.0:80->8080/tcp Focused_poincare

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

SSH root@127.0.0.1-p 49154

Input can be password, is not accessible. Once you control ssh, the rest is simple, install the JDK, install tomcat, whatever you want. The following is an installation script:

# Install Oracle JDK 7
apt-get install python-software-properties add-apt-repository ppa:webupd8team/on Ubuntu
12.04 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
# Extract, run
tar xvf apache-tomcat-7.0.47.tar.gz
CD apache-tomcat-7.0.47
bin/startup.sh

By default, Tomcat consumes the 8080 port, and just when the mirror instance is started, the-p 80:8080,ubuntu Mirror Instance/container is specified, opening port 8080, and mapping to the host port is 80. Know the host IP address, it is free to access. On the host, through the Curl test can be:

Curl http://192.168.190.131

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

In reality, Tomcat may not be able to open the 80 port directly to the Nginx/apache or behind the firewall, just for demonstration. Summary

With the help of Docker to build a tomcat runtime environment, the overall is very simple, let us see the PAAs figure. Yes, using Docker as the PAAs underlying service is not inherently complex. Here are some time to talk about how to use script file to build a mirror instance, and talk about the principle and mechanism of Docker

Related Article

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.