This article transferred from: http://www.blogjava.net/yongboy/archive/2013/12/12/407498.html
Objective
Docker is designed to provide an automated deployment solution for an application that quickly creates a container (lightweight virtual machine) on a Linux system and deploys and runs the application, making it easy to automate the installation, deployment, and upgrade of applications with configuration files. Because of the use of containers, it can be very convenient to the production environment and development environment, independent of each other, this is the most common Docker play. More gameplay also include large-scale Web applications, database deployment, continuous deployment, clustering, test environments, service-oriented cloud computing, virtual desktop VDI, and more.
Subjective impression: Docker uses Go language to write, uses Cgroup realizes the resource isolation, the container technology uses the 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 complex, if interested, here is an article I wrote previously based on LXC, (<ahref= "http:www.blogjava.=" "net=" "yongboy=" "archive=" "2012 =" "06 =" "23 =" " 381346.html "=" "> From scratch, build a simple version of the Java PAAs Cloud platform), you can review in advance.
The implementation principles, related theories, application scenarios, etc., will be written later in this series, here first a scratch, completely manual, based on Docker to build a tomcat operating environment. First out a smarty pants demo, you can see the effect, may let us go farther.
Environment
In all environments, VMware workstation runs UBUNTU-13.10-SERVER-AMD64 on a 64-bit system, and theoretically other virtual machines are perfectly viable.
Installing Docker
The Docker 0.7 version requires Linux kernel 3.8 support and requires a Aufs file system.
# 添加Docker repository,并安装Dockersudo sh -c "echo deb http://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"
sudo apt-get updatesudo apt-get install lxc-docker# 检查Docker是否已安装成功sudo docker version# 终端输出 Client version: 0.7.1Go version (client): go1.2Git commit (client): 88df052Server version: 0.7.1Git commit (server): 88df052Go version (server): go1.2Last stable version: 0.7.1
Remove sudo
Under Ubuntu, in the execution of Docker, every time you have to input sudo, and enter the password, very tiring, here to fine-tune, the current user execution permissions added to the appropriate Docker user group.
# 添加一个新的docker用户组sudo groupadd docker# 添加当前用户到docker用户组里,注意这里的yongboy为ubuntu server登录用户名sudo gpasswd -a yongboy docker# 重启Docker后台监护进程sudo service docker restart# 重启之后,尝试一下,是否生效docker version#若还未生效,则系统重启,则生效sudo reboot
Install a Docker run instance-ubuntu virtual machine
The Docker installation is complete, and the background process starts automatically, so you can install the virtual machine instance (here is an example of the learn/tutorial image used by the official demo):
docker pull learn/tutorial
After the installation is complete, look at the effect
docker run learn/tutorial /bin/echo hello world
Interactively entering a newly installed virtual machine
docker run -i -t learn/tutorial /bin/bash
will see:
Description has entered the interactive environment.
Install SSH Terminal Server, easy for us to use SSH client login access
apt-get updateapt-get install openssh-serverwhich sshd/usr/sbin/sshdmkdir /var/run/sshdpasswd #输入用户密码,我这里设置为123456,便于SSH客户端登陆使用exit #退出
Gets the instance container ID of the action that was just
#docker ps -lCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES51774a81beb3 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 you have done all the work, you will need to commit the save and make it easy for SSH to log in:
docker commit 51774a81beb3 learn/tutorial
This mirrored instance is run for a long time in the next process mode:
docker run -d -p 22 -p 80:8080 learn/tutorial /usr/sbin/sshd -D
The SSH server running in the Ubuntu container occupies Port 22, which is specified by-p. - p 80:8080 means that our Ubuntu will run Tomcat on port 8080, but the external (out-of-container) mapped port is 80.
At this point, check to see if it runs successfully.
#docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES871769a4f5ea 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 here that the assigned random SSH connection port number is 49154:
ssh [email protected] -p 49154
Input can be password, is it possible to enter? Once you control ssh, the rest is simple, install the JDK, install Tomcat, and so on, whatever you want. The following is the installation script:
# 在ubuntu 12.04上安装oracle jdk 7apt-get install python-software-propertiesadd-apt-repository ppa:webupd8team/javaapt-get updateapt-get install -y wgetapt-get install oracle-java7-installerjava -version# 下载tomcat 7.0.47wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz# 解压,运行tar xvf apache-tomcat-7.0.47.tar.gzcd apache-tomcat-7.0.47bin/startup.sh
By default, Tomcat consumes the 8080 port, and just when you start a mirrored instance, you specify the-p 80:8080,ubuntu mirror instance/container, open port 8080, and map to the host port is 80. If you know the host IP address, you are free to access it. On the host, you can test it with curl:
curl http://192.168.190.131
Of course, you can also use a browser to access it.
True, it may not allow Tomcat to open the door directly to port 80, which is usually located behind the Nginx/apache or the firewall, just for demonstration.
Summary
With the help of Docker to build a tomcat runtime environment, the overall is simple, let us see the PAAs figure. Yes, using Docker as the underlying service for PAAs is not inherently complex. Here's the time to talk about how to use a script file to build a mirrored instance, and talk about the implementation principles and mechanisms of Docker.
--------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- --------------------------------------------------------------------------------------------------------------- -
Please try a few more times, as the well-known cuss of the Great Gfw,apt-get update and Docker pull may go wrong.
Off-topic: learn technology, but don't tyrant
Go One of the Docker learning notes to build a Java Tomcat runtime environment