Build an image based on CentOS 7, including Java 8, Tomcat 7,php, Mysql+mycat, using Dockerfile

Source: Internet
Author: User
Tags docker run

Dockerfile content is as follows:

 fromCentOSMaintainer Victor [email protected]Workdir /RootRUNRm-f/etc/yum.repos.d/*RUNEcho'[BASE]'>/etc/yum.repos.d/Base.repoRUNEcho'Name=base'>>/etc/yum.repos.d/Base.repoRUNEcho'baseurl=http://192.168.244.132/yum/mnt'>>/etc/yum.repos.d/Base.repoRUNEcho'enabled=1'>>/etc/yum.repos.d/Base.repoRUNEcho'gpgcheck=0'>>/etc/yum.repos.d/Base.repoADD/mysql/MySQLRUNYum-y Install java-1.8.0-OPENJDK wget httpd php php-mysqlnd/mysql/*RUNmysql_install_db--user=MySQLENV mysql_root_password=123456 env mycat_user mycatenv mycat_pass mycatRUNwget http://mirror.bit.edu.cn/apache/tomcat/tomcat-7/v7.0.64/bin/apache-tomcat-7.0. -. tar.gzRUNTar xvf apache-tomcat-7.0. -. tar.gz-c/usr/local/&& mv/usr/local/apache-tomcat-7.0. -//usr/local/TomcatRUNwget http://code.taobao.org/svn/openclouddb/downloads/old/mycat-sever-1.2/mycat-server-1.2-ga-linux.tar.gzRUNMkdir/usr/local/mycat && tar xvf mycat-server-1.2-ga-linux.tar.gz-c/usr/local/mycat && useradd mycat && \Chown-R mycat.mycat/usr/local/mycat && chmod a+x/usr/local/mycat/bin/*EXPOSE8080 8066 9066 COPY startup.sh/root/startup.shRUNchmod a+x/root/startup.shentrypoint /root/startup.sh

The description is as follows:

1. The following is used to build the Yum source, because the company network is limited, the installation of the process of relying on the package of people tears ... It is decisive to use the host's system CD to build HTTP yum source.

RUNRm-f/etc/yum.repos.d/*RUNEcho'[BASE]'>/etc/yum.repos.d/Base.repoRUNEcho'Name=base'>>/etc/yum.repos.d/Base.repoRUNEcho'baseurl=http://192.168.244.132/yum/mnt'>>/etc/yum.repos.d/Base.repoRUNEcho'enabled=1'>>/etc/yum.repos.d/Base.repoRUNEcho'gpgcheck=0'>>/etc/yum.repos.d/base.repo

2. Because the CentOS 7 system CD does not have its own mysql-server, it needs to download itself, just right, the MySQL community also provides a mysql-serve-based Yum source, just/etc/yum.repos.d/ Under directory, add the following file Mysql-community.repo file, which reads as follows:

[mysql56-Community]name 5.6 Community serverbaseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/ enabled=1gpgcheck=0

Even in this way, the download process is also extremely frustrating, helpless, had to download the relevant RPM package, put in the local MySQL directory, through the Add command to copy the files in the directory into the Mirror. Note:/mysql is a relative path relative to Dockerfile, because the absolute path of my Dockerfile is/root/dockerfile, so the absolute path in/mysql below is actually/root/mysql/.

ADD /mysql/mysql

The files in/root/mysql are as follows:

[Email protected] ~]#ls/root/mysql/MySQL-5.6. --2. el5.x86_64.rpm mysql-community-libs-5.6. --2. El5.x86_64.rpmmysql-community-client-5.6. --2. el5.x86_64.rpm mysql-community-libs-compat-5.6. --2. El5.x86_64.rpmmysql-community-common-5.6. --2. el5.x86_64.rpm mysql-community-server-5.6. --2. el5.x86_64.rpm

3. The final step is actually started with a script

The script reads as follows:

[Email protected] ~]#Cat/root/startup.SH #!/bin/Bashsed-I.'s/user name= "test"/user name=\ "' "$MYCAT _user"'"/'/usr/local/mycat/conf/Server.xmlsed-I.'s/name= "password" >test/name= "password" >' "$MYCAT _pass"'/'/usr/local/mycat/conf/Server.xmlmysqld_safe&/usr/local/mycat/bin/mycat Start & httpd &/usr/local/tomcat/bin/catalina.SHRun

In this startup script, the user name and password of the Mycat are set by using the parameters, and the user name and password are specified in the following variables in the Dockerfile:

ENV mycat_user mycatenv Mycat_pass mycat

Note: When creating a container based on this image, you can also specify the values of the above two parameters through the-e parameter dominance, and if not specified, the default value for the user name and password is the mycat specified in Dockerfile.

Verify the following:

1. Create a mirror based on Docker

# docker Build-t Victor/mycat:v1.

Recommendation: when building a mirror with Dockerfile, the--rm=false parameter, Docker build-rm=false-t Victor/mycat:v1, can be taken. means that the intermediate container produced during the build image is not deleted, This way, even if this build fails, it will be much easier and quicker to use the cache container directly when building again.

2. View the generated image

[Email protected] ~]# Docker imagesrepository          TAG                 IMAGE ID            CREATED             VIRTUAL sizevictor/mycat        v1                  5091cdf7b73a        2 hours ago         1.058 GB

3. Running the container

# docker Run-p 8080:8080-p 9066:9066-p 8066:8066-p 81:80 victor/mycat:v1

First verify that Tomcat is started

Verify that Apache is starting up again, in order to avoid conflicts with the local HTTP Yum source, I'm using the 80 port of the host's 81 port mapping container.

To verify that the Mycat is working properly

It is not difficult to see that the default username and password based on Mycat is denied and must be specified with the user name and password.

Resources:

1> Mycat_ Installation Guide (Linux). doc https://github.com/MyCATApache/Mycat-doc/tree/master/%E5%85%A5%E9%97%A8%E6%8C%87%E5%8D%97

2> Mysql Yum Source Address http://repo.mysql.com/yum/mysql-5.6-community/el/5/x86_64/

3> CentOS Yum Install Apache + PHP + Tomcat7 + MySQL http://www.cnblogs.com/jifeng/p/4074591.html

Build an image based on CentOS 7, including Java 8, Tomcat 7,php, Mysql+mycat, using Dockerfile

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.