Understanding docker
docker is an open source application container engine, docker using the Linux Kernel Virtual Machine Technology (LXC), provide lightweight virtualization isolate processes and resources. LXC than hardware virtualization, it is the Linux kernel-level virtual machine technology, compared with traditional virtual machines, saving a lot of hardware resources. docker allows developers to easily packaged applications to a portable, lightweight containers, simple and quick. Between the container using sandboxing, relatively closed to each other directly, the performance overhead of the container is low.
Advantages:
. 1) Docker simplifies the process of deployment, as long as the package will be applied to the container, the container can run on Linux;
2) Docker start faster than many of the virtual machine;
. 3) on the resource utilization ratio Docker Virtual many high machine, you can run multiple containers on the same server, but it is difficult to run multiple virtual machines.
4) docker save money, developers do not have to be efficient performance and buy more hardware, virtualization can be achieved docker distributed and clustered on a small number of servers.
docker installation
docker in the can support Linux3.8 kernel, but it seems not so ideal, can be better compatible Linux3.10 and above, for centos, you can select the version 7.0 and above. If the kernel is low you can upgrade the kernel.
1, upgrade the kernel
1) Check the kernel
uname -r
2) update yum
sudo yum update
. 3) by the kernel upgrade yum
yum install -y kernel
4) to restart the system
shutdown -r now
2, installation docker
yum install -y docker-io
启动docker
systemctl start docker
加入开启重启项
systemctl enable docker
查看docker版本
docker version
3, install Tomcat
1) Find a docker Mirror
docker search tomcat
2) The drag down image (usually selected first, i.e. the largest number of star, use the name for pull)
docker pull docker.io/tomcat
3) View Mirror
docker images
4) Start Tomcat container
docker run -d --name fist_tomcat --privileged=true -e TZ="Asia/Shanghai" -v /etc/localtime:/etc/localtime -d -p 8081:8080 docker.io/tomcat
Parameter Description
-d expressed in "guard mode" /root/run.sh script execution, this time Tomcat console does not appear on the output terminal.
-p indicates the host port mapping (8081) of the container (8080, the Tomcat container fixed port 8080, must be mapped to 8080)
-name represents the name of the container, with a meaningful name can be named.
-v which expressed the need for local directory is mounted to the container, format: -v <host directory>: <Container Catalog>
-e run Shanghai time zone format
-privileged = true privilege to open, you can set the containers kernel parameters
-e TZ="Asia/Shanghai" -v /etc/localtime:/etc/localtime
are to solve the problem of time zones container
of course you can also enter a container modification area
saw a bunch of strings illustrate the successful launch of
4) View container
docker ps -s
5) into the container (here using container name)
docker exec -it 容器id\容器名称 bash
area found when viewing the right
if the time zone is incorrect may be inside the container change the time zone
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
and then exit the container
exit
restart the container
docker restart 容器id/容器名称
6) View jdk (first to enter the container)
4, run the project in Tomcat
1) can run the project by mounted (leaving aside here presentations)
2) can be copied to the project running in the container
first item copied to / home / work in
copy items to the container
docker cp /home/work/hello.war 容器id/容器名称:/usr/local/tomcat/webapps
start container
docker restart 容器id/容器名称