In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
This article is mainly about how to build a Nginx+Tomcat+MYSQLDocker container. If you are interested, let's take a look at this article. I believe it is of some reference value to you after reading how to build a Nginx+Tomcat+MYSQLDocker container.
First, build a Nginx container
Nginx is not only a lightweight WEB cloud server, but also an excellent reverse proxy cloud server. Nginx service occupies less memory and has strong concurrency ability, so it is deeply welcomed by users at home and abroad.
1. Download the basic image [root@localhost ~] # docker pull docker.io/lvzhenjiang/centos7// download a basic centos image that creates a Nginx image. Set up a working directory [root@localhost ~] # mkdir nginx [root@localhost ~] # cd nginx/3. Create and write the Dockerfile file [root@localhost nginx] # vim DockerfileFROM lvzhenjiang/centos7 / / set up the basic image MAINTAINER lzj / / maintainer information RUN yum-y install wget prce-devel net-tools gcc zlib zlib-devel make openssl-devel / / install the required dependency package RUN wget http://nginx.org/download/nginx-1.14.2.tar.gz / / obtain the decompressed nginx source package RUN tar zxf nginx-1.14.2.tar.gzWORKDIR nginx-1.14.2// and enter the decompressed directory RUN. / configure-- prefix=/usr/local/nginx & & make & & make install// compilation and installation EXPOSE 80 / / Open port 80 EXPOSE 443 / / Open port 443 RUN echo "daemon off "> > / usr/local/nginx/conf/nginx.conf// modifies the nginx service configuration file, starts ADD run.sh / run.sh / / uploads locally written scripts to the container in a non-daemon (daemon) mode, RUN chmod 775 / run.sh / / gives the script execution permission CMD [" / run.sh "] / / starts the container, executes run.sh script 4. Write and execute the content of the script [root@localhost nginx] # vim run.shrun.shrun.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Generate image [root@localhost nginx] # ls / / make sure the Dockerfile file and startup script are in the same directory Dockerfile run.sh [root@localhost nginx] # docker build-t nginx:v1. / / use the Dockerfile file in the current directory to generate a new image, named nginx:v16. Launch the container to test [root@localhost nginx] # docker run-dit-p 12345 dit 80-- name nginx nginx:v1// creates a container called nginx using the newly generated image And map port 80 in the container to port 12345 of the host [root@localhost nginx] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1c73bb591e84 nginx:v1 "/ run.sh" 31 minutes ago Up 31 minutes 443/tcp 0.0.0.0 80/tcp nginx// 12345-> confirm that the container is running properly and that the port has been mapped
Test results:
The nginx container is built!
Second, build a Tomcat container
Tomcat is a free and open source lightweight Web cloud server, which is widely used in small and medium-sized enterprises and situations with low concurrency. It is the first choice for developing and debugging JSP programs.
1. Download the basic image [root@localhost ~] # docker pull docker.io/lvzhenjiang/centos7// download a basic centos image that creates a Nginx image. Create a working directory
Because tomcat requires a java environment, download the JDK package
[root@localhost] # mkdir tomcat [root@localhost ~] # cd tomcat/3. Write Dockerfile file [root@localhost tomcat] # vim Dockerfile FROM lvzhenjiang/centos7 / / basic image MAINTAINER lzj / / maintainer information ADD jdk1.8.0_91 / usr/local/jdk-8u91ENV JAVA_HOME / usr/local/jdk-8u91ENV JAVA_BIN / usr/local/jdk-8u91/binENV JRE_HOME / usr/local/jdk-8u91/jreENV PATH $PATH:/usr/local/jdk-8u91/ Bin:/usr/local/jdk-8u91/jre/binENV CLASSPATH / usr/local/jdk-8u91/jre/bin:/usr/local/jdk-8u91/lib:/usr/local/jdk-8u91/jre/lib/charsets.jar// sets the JDK environment variable RUN yum-y install wgetRUN wget http://us.mirrors.quenda.co/apache/tomcat/tomcat-9/v9.0.27/bin/apache-tomcat-9.0.27.tar.gz// to get the tomcat software package After decompression of RUN tar zxf apache-tomcat-9.0.27.tar.gzRUN mv apache-tomcat-9.0.27 / usr/local/tomcat// When you move the unzipped directory to the specified location EXPOSE 8080max / open port 8080 ADD run.sh / run.shRUN chmod 775 / run.shCMD ["/ run.sh"] / / start the container, execute script 4. Write a startup script [root@localhost tomcat] # vim run.sh #! / bin/bash/usr/local/tomcat/bin/startup.sh / / start the service tailf / run / / using the script that comes with the tomcat service so that the startup script always runs 5. Use Dockerfile file to generate image [root@localhost tomcat] # lsDockerfile jdk1.8.0_91 run.sh// make sure everything needed in Dockerfile file is in this directory [root@localhost tomcat] # docker build-t tomcat:v1. / / use the Dockerfile file in the current directory to generate image 6 named tomcat:v1. Run the container and verify that [root@localhost tomcat] # docker run-dit-p 12344 name tomcat tomcat:v1// uses the newly generated to create a container named tomcat And map port 8080 in the container to port 12344 of the host [root@localhost tomcat] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1ffc46084d84 tomcat:v1 "/ run.sh" 10 minutes ago Up 10 minutes 0.0.0.0 aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1ffc46084d84 tomcat:v1 12344 -> 8080/tcp tomcat// ensures that the container has been started And the port has been mapped
Access Test:
The tomcat container is built!
Third, build a MySQL container
MySQL is the most popular relational database, and the SQL language used is the most commonly used standardized language for accessing the database. MySQL has the advantages of small size, high speed and low cost, so it has become the preferred database for small and medium-sized enterprises.
1. Download the basic image [root@localhost ~] # docker pull docker.io/lvzhenjiang/centos6// download the basic image of centos6 as the basic image of building MySQL 2. Create a working directory [root@localhost ~] # mkdir mysql [root@localhost ~] # cd mysql/3. Create Dockerfile file [root@localhost mysql] # vim DockerfileFROM lvzhenjiang/centos6 / / basic image MAINTAINER lzj / / maintainer information RUN yum-y install mysql mysql-server / / install mysqlRUN / etc/init.d/mysqld start & &\ mysql- e "grant all privileges on *. * to 'root'@'%' identified by' 123456' "&\ mysql-e" grant all privileges on *. * to 'root'@'localhost' identified by' 123456launch; / / start the MySQL service and authorize the user EXPOSE 3306 / / to open port 3306 CMD ["mysqld_safe"] / / start service 4 using the startup script that comes with MySQL. Generate an image [root@localhost mysql] # lsDockerfile [root@localhost mysql] # docker build-t mysql:v1. / / generate an image named mysql:v1 using the Dockerfile file in the current directory. Create a container and test [root@localhost mysql] # docker run-dit-p 12343dit 3306-- name=mysql mysql:v1// uses mysql:v1 's image to generate a container called mysql And map port 3306 in the container to port 12343 of all hosts [root@localhost mysql] # docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc356d5b35167 mysql:v1 "mysqld_safe" 4 seconds ago Up 3 seconds 0.0.0.0 aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESc356d5b35167 mysql:v1 12343-> 3306 / tcp / / confirm that the container is running properly And port mapping has been started
Host for testing:
[root@localhost] # yum-y install mysql / / first install the mysql command [root@localhost] # mysql-u root-h 127.0.0.1-P 12343-p123456Welcome to the MariaDB monitor. Commands end with; or\ g.Your MySQL connection id is 1Server version: 5.1.73 Source distributionCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type 'help;' or'\ h' for help. Type'\ c' to clear the current input statement.MySQL [(none)] > / / access succeeded
Does the above details on how to build Nginx+Tomcat+MYSQLDocker containers help you? If you want to know more about it, you can continue to follow our industry information section.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.