Building Nginx,tomcat,mysql Images with Dockerfile

Source: Internet
Author: User
Tags docker run

Lab Environment Description
本机IP地址:192.168.10.157构建mysql镜像时,验证的主机IP;192.168.10.149
Build nginx image 1, download the base image--centos image
docker pull centos
2. Create a working directory
mkdir /opt/nginxcd /opt/nginx/
3. Create and write Dockerfile files
vim DockerfileFROM centosMAINTAINER this is nginx image <xxy>RUN yum install -y wget proc-devel net-tools gcc zlib zlib-devel make openssl-develRUN wget http://nginx.org/download/nginx-1.9.7.tar.gzRUN tar zxvf nginx-1.9.7.tar.gzWORKDIR nginx-1.9.7RUN ./configure --prefix=/usr/local/nginx && make && make installEXPOSE 80           //httpEXPOSE 443              //httpsRUN echo "daemon off;">>/usr/local/nginx/conf/nginx.conf     //关闭守护进程WORKDIR /opt/nginxADD run.sh /run.sh       //将宿主机中的run.sh添加到容器中RUN chmod 755 /run.shCMD ["/run.sh"]

4. Write Execution script content
vim run.sh#!/bin/bash/usr/local/nginx/sbin/nginx

5. Create image
docker build -t nginx:new .docker images           //查看镜像


6. Start the container for testing
docker run -d -P nginx:new        //启动容器,-p随机指定宿主机端口映射容器中nginx服务相关端口docker ps -a      //查看容器   

浏览器输入:http://192.168.10.157:32769/

Build Tomcat image 1, create a working directory, extract the related packages to the working directory
mkdir /opt/tomcat     //创建工作目录cp jdk-8u91-linux-x64.tar.gz /opt/tomcat/cp apache-tomcat-8.5.16.tar.gz /opt/tomcat/     //移动到工作目录cd /opt/tomcat/tar zxvf jdk-8u91-linux-x64.tar.gztar zxvf apache-tomcat-8.5.16.tar.gz        //解压软件包
2. Create a Dockerfile file
vim DockerfileFROM centosMAINTAINER this is tomcat image <xxy>ADD jdk1.8.0_91 /usr/local/javaENV JAVA_HOME /usr/local/javaENV JAVA_BIN /usr/local/java/binENV JRE_HOME /usr/local/java/jreENV PATH $PATH:/usr/local/java/bin:/usr/local/java/jre/binENV CLASSPATH /usr/local/java/jre/bin:/usr/local/java/lib:/usr/local/java/jre/lib/charsets.jarADD apache-tomcat-8.5.16 /usr/local/tomcat8EXPOSE 8080

3. Create image
docker build -t tomcat:centos .

4. Run the container and verify
docker run --name tomcat01 -p 80:8080 -it  tomcat:centos /bin/bash          //运行容器,将本地80端口映射到容器的8080端口[[email protected] bin]#cd /usr/local/tomcat8/bin[[email protected] bin]#./startup.sh      //容器中启动Tomcat

浏览器输入:http://192.168.10.157/

Build MySQL image 1, download the image, it is recommended to use CENTOS6 image
docker pull guyton/centos6

2. Create a working directory
mkdir /opt/mysqlcd /opt/mysql
3. Create a Dockerfile file
vim DockerfileFROM guyton/centos6MAINTAINER this is msyql images <xxy>RUN yum install mysql mysql-serverRUN /etc/init.d/mysqld start &&mysql -e "grant all privileges on *.* to ‘root‘@‘%‘ identified by ‘abc123‘;" &&mysql -e "grant all privileges on *.* to ‘root‘@‘localhost‘ identified by ‘abc123‘;"      //root在本地,非本地登录时都使用abc123密码EXPOSE 3306CMD ["mysqld_safe"]

4. Create image
docker build -t centos6:mysql .docker images      //查看镜像

5. Run the container and verify
docker run --name=mysqlserver -d -P centos6:mysql       //运行容器,随机指定本机端口映射容器mysql的端口docker ps -a    //查看容器

On the host hosting the MySQL service, or the MySQL service installed on this computer, log in to the container's MySQL database for verification
mysql -h 192.168.10.157 -u root -P 32770 -pabc123

Building Nginx,tomcat,mysql Images with Dockerfile

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.