Details on the use of Docker 7 docker in aliyun

  • 2020-05-24 06:37:47
  • OfStack

In the traditional model, the development team completed the software development in the development environment, and did the unit test once, which passed. To the code version management library. Operations deploys the application to the test environment, QA tests it, and notifies the deployer to release it to the production environment when there is no problem. At least three environments are involved in the above process: development, testing, and production. In reality, there is no problem with self-test of development, but when it comes to test or production environment, the program cannot be run, so the development team is asked to check. After a long time of checking, it turns out that one of the third party libraries in the test environment is out of date. This phenomenon is so common in software development that it is no longer suitable for today's rapid development and deployment. docker can meet your needs.

Ali cloud container hub developer platform, you can go here to download the required image

https://dev.aliyun.com/search.html?spm=5176.1972343.0.1.MSG1P3

It is important to look at the kernel version first


# uname -a

Check the kernel version of the system, docker requires the kernel version of 3.10 or above, it is recommended (do not install docker on centos6.6, there are many pits, I am one step over)

I use the ECS centos 6.6 64-bit version of aliyun, so I need to upgrade the kernel version.


# rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# rpm -Uvh http://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-lt -y
# vim /etc/grub.conf
default=0  the default=1  Instead of default = 0

Finally restart the server

Start installing docker


# curl -sSL https://get.docker.com/ | sh 
# docker --version
Docker version 1.7.1, build 786b29d
# vim /etc/sysconfig/docker 
other_args="--registry-mirror=https://rr8hxwoy.mirror.aliyuncs.com -H tcp://0.0.0.0:235 -H unix:///var/run/docker.sock"  Configure aliyun acceleration  docker pull Will soon 

Start the docker


# /etc/init.d/docker start
# chkconfig docker on

Run the docker container


# docker pull centos
latest: Pulling from centos
3690474eb5b4: Already exists 
af0819ed1fac: Already exists 
05fe84bf6d3f: Already exists 
97cad5e16cb6: Already exists 
Digest: sha256:934ff980b04db1b7484595bac0c8e6f838e1917ad3a38f904ece64f70bbca040
Status: Image is up to date for centos:latest

Pull the centos image from aliyun private mirror warehouse to the local, because aliyun image is configured to speed up, so the download is very fast, 30 seconds.


# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest 97cad5e16cb6 12 days ago 196.5 MB
# docker run -d -it centos /bin/bash  run centos The container 
# docker ps -a 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
969ad48e4085 centos "/bin/bash" 5 seconds ago Up 4 seconds jovial_torvalds
# docker exec -it 969a /bin/bash  Into the container  969a Is the container ID

The Docker startup container command has been described in detail in the previous section. For those who don't know, please visit my previous blog

The key to the

java+tomcat are used in containers

The test environment server was configured with centos 6.6 64-bit, 4-core processor, and 8G memory

Theoretically, it can run 16 java containers, because each container consumes around 500M of memory. I ran 8 java containers on it, another 1 nginx as a reverse proxy and 1 redis. Neither nginx nor redis used docker

Download jdk1.7.0.72 and tomcat and put them in the same level 1 directory as Dockerfile


vim Dockerfile
#This is My first Dockerfile
#version 1.0
#Base image 
FROM centos:latest
#MAINTAINER hh Wang
#ADD
ADD jdk1.7.0_72.gz /usr/local/
ADD biz-tomcat.tar.gz /usr/local/
#RUN
RUN yum -y install wget gcc gcc-c++ make openssl openssl-devel net-tools vim
RUN mkdir /docker/myapp/ROOT -p
#ENV
ENV JAVA_HOME /usr/local/jdk1.7.0_72
ENV JRE_HOME $JAVA_HOME/jre
ENV CLASSPATH .:$JAVA_HOME/lib:$JRE_HOME/lib
ENV PATH $PATH:$JAVA_HOME/bin
ENV CATALINA_HOME /usr/local/biz-tomcat
EXPOSE 8080
CMD ["/usr/local/biz-tomcat/bin/catalina.sh","run"]
# docker build -t whh/biz_tomcat:v1 .  behind 1 A point, 1 Need to remember 
# docker run -it -d -v /mnt/docker/myapp/ROOT/biz:/docker/myapp/ROOT -v /var/log/biz-tomcat/logs:/usr/local/biz-tomcat/logs -p 9080:8080 --name biz whh/biz_tomcat:v1

tomcat the root directory of the prior to modify the path for you need, I am here for docker/myapp/ROOT, hang in the root directory of the host machine/mnt/docker/myapp/ROOT/biz directory below, when updating the code, the code directly to the directory, and then restart the one container is ok, don't need to upload the code to a container, that would be trouble.


[root@VM_159_91_centos biz]# docker ps -a 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
969ad48e4085 centos "/bin/bash" 21 minutes ago Up 21 minutes jovial_torvalds 
f67257661e70 registry "/entrypoint.sh /etc 7 hours ago Up 7 hours 0.0.0.0:5000->5000/tcp high_darwin 
4bcc381f5b9f whh/biz_tomcat:v1 "/usr/local/biz-tomc 9 hours ago Up 7 hours 0.0.0.0:9080->8080/tcp biz
# docker tag whh/biz_tomcat:v1 IP:5000/whh/biz_tomcat:v1 IP Write your own Intranet IP Or public IP Can be 
# docker push IP:5000/whh/biz_tomcat:v1  Push to your own private repository, directly from other servers pull To use 
00:19:15 2016-11-16

Related articles: