In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Blog outline:
First, build Nginx container 2, build Tomcat container 3, build MySQL container
Note: be sure to configure the host to connect to the Internet, because in the process of building the container, many resources need to be found on the Internet.
First, build a Nginx container
Nginx is a lightweight web server and an excellent reverse proxy server. Nginx service takes up less memory and has strong concurrency ability. Here are the specific operations for building a Nginx container:
[root@localhost ~] # docker pull centos # download the basic image of centos 7, which will also be used by the Tomcat and MySQL containers built later. [root@localhost ~] # mkdir nginx # create a working directory [root@localhost ~] # cd nginx/ [root@localhost nginx] # vim Dockerfile # write dockerfile files Used to implement the Nginx installation process # write the following content FROM centos # set up the basic image MAINTAINER the centos project # maintain the user information of the image RUN yum-y install wget proc-devel net-tools gcc zlib zlib-devel make openssl-devel # install the dependent package RUN wget http://nginx.org/download/nginx-1.9.7.tar.gz # download the Nginx source package RUN tar zxf nginx-1.9.7 .tar.gz # decompress the downloaded source package WORKDIR nginx-1.9.7 # specify the working path in the container RUN. / configure-- prefix=/usr/local/nginx & & make & & make install # configuration and compilation installation # Open the container's 80 EXPOSE port 443 EXPOSE 80 EXPOSE 443RUN echo "daemon off "> > / usr/local/nginx/conf/nginx.conf # modify the configuration file and start ADD run.sh / run.sh # upload the running script RUN chmod 775 / run.sh # in a non-daemon way. Give the script permission CMD [" / run.sh "] # execute the script when you start the container. After editing, save and exit [root@localhost nginx] # vim run.sh # to edit and run the script. Write the following #! / bin/bash/usr/local/nginx/sbin/nginx [root@localhost nginx] # ls # to make sure that the following file Dockerfile run.sh [root@localhost nginx] # docker build-t nginx:ljz exists in the current directory. # to generate an image, do not ignore the dot at the end of the command "." Otherwise, an error will be reported.. # omitting part of the content Successfully built cd6ac93f3680 # this prompt message appears, it means that [root@localhost nginx] # docker run-d-P nginx:ljz # has been created successfully, and "- d" means persistent operation. "- P" means to map the port of the container to the host 895c19da98f3256acb20939dcc7abb4d26273287ddfc0810efc0940a55d04c10 [root@localhost nginx] # docker ps-a # View the container 32769 and 32768 are the ports CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES895c19da98f3 nginx:ljz "/ run.sh" 6 seconds ago Up 5 seconds 0.0.0.0 seconds ago Up 32769-> 80/tcp on which the container is mapped to the host. 0.0.0.0VOVA 32768-> 443/tcp nervous_brahmagupta
Visit the container to test whether Nginx is running successfully! As follows (accessing port 32769 of the host is equivalent to accessing port 80 of the container):
Second, build a Tomcat container
Tomcat is a free and open source lightweight web server, which is widely used in small and medium-sized enterprises and low concurrency. It is the first choice for developing and debugging JSP programs. Let's use the Dockerfile file to create an docker image with a Tomcat service.
Preparation: click to download the JDK source package and place the Tomcat working directory of the Linux host.
[root@localhost ~] # mkdir tomcat # create a working directory for Tomcat [root@localhost ~] # cd tomcat/ # switch to the Tomcat directory [root@localhost tomcat] # rz # I upload the local JDK source code package (I use a xshell connection here) [root@localhost tomcat] # ls # View jdk-8u91-linux -x64.tar.gz [root@localhost tomcat] # tar zxf jdk-8u91-linux-x64.tar.gz # unpack [root@localhost tomcat] # vim Dockerfile # write dockerfile file FROM centos # basic image centosMAINTAINER The centos project ljz916551516@163.com # maintain the image's user information ADD jdk1.8.0_91 / usr/local/jdk-8u91 # upload the local JDK file below Container # Is to set the JDK environment variable ENV JAVA_HOME / usr/local/jdk-8u91 ENV 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.jarRUN yum-y Install wget # install wget tools RUN wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-8/v8.5.38/bin/apache-tomcat-8.5.38.tar.gz# download Tomcat source package RUN tar zxf apache-tomcat-8.5.38.tar.gz # decompress Tomcat source package RUN mv apache-tomcat-8.5.38 / usr/local/tomcat # move to the installation directory EXPOSE 8080 # open Port 8080 ADD run.sh / run.sh # add run script RUN chmod 775 / run.sh # give script execution permission CMD ["/ run.sh"] # run script After you have finished writing, save and exit. [root@localhost tomcat] # vim run.sh # write and execute script content #! / bin/bash/usr/local/tomcat/bin/startup.shtailf / run [root@localhost tomcat] # ls # make sure the following file Dockerfile jdk1.8.0_91 jdk-8u91-linux-x64.tar.gz run.sh [root@localhost tomcat] # docker build-t tomcat:ljz is in the current directory. # to generate an image, do not ignore the dot at the end of the command "." Otherwise, an error will be reported.. # omitting part of the content Successfully built 94c59c9239ec # this message appears, it means that [root@localhost tomcat] # docker run-d-- name tomcat-p 8080 docker run 8080 tomcat:ljz# has been created successfully, and specify the name of the container as Tomcat. Map to port 8080 of the host. 5d8a5714166ef63208511bb1123c5568d0562b1b3734db4eec2aed733d8a733d [root@localhost tomcat] # docker ps-a | grep tomcat # check whether the status of the Tomcat container is normal 5d8a5714166e tomcat:ljz "/ run.sh" 20 seconds ago Up 19 seconds 0.0.0.0 docker ps 8080-> 8080/tcp tomcat
The client accesses port 8080 of the Linux host to test whether it can access the web service provided by the Tomcat container, as follows:
When you see the above page, the Tomcat container is built successfully.
Here's a brief description of the difference between Tomcat and apache: they are both projects developed by the Aache open source organization to handle HTTP services. Both are free and can be run as stand-alone web servers. Apache is implemented in C language, mainly parsing static text with high concurrency, focusing on HTTP services. Tomcat is a JavaEES-compliant JSP server developed by java, which belongs to the extension of Apache. It is mainly used to parse JSP/Servlet, focusing on Servlet engine.
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, and is the preferred database for small and medium-sized enterprises.
Start building the MySQL container:
[root@localhost ~] # docker pull docker.io/guyton/centos6 # download centos6 as the basic image [root@localhost ~] # mkdir mysql # create a working directory [root@localhost ~] # cd mysql/ # cut into the working directory [root@localhost mysql] # vim Dockerfile # Edit the dockerfile file FROM guyton/centos6MAINTAINER the centos project-mysqlRUN yum-y install mysql mysql-serverRUN / 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' 123456; "EXPOSE 3306CMD [" mysqld_safe "] [root@localhost mysql] # docker build-t mysql:ljz. # to generate an image, do not ignore the dot at the end of the command "." Otherwise, an error will be reported.. # omitting part of the content Successfully built 30414dc7bc02 # this prompt appears, it means that [root@localhost ~] # docker run-d-name mysql-P mysql:ljz # running container has been created successfully. And define the container name as mysqlea1a8aa2d1f18e0d06c4bdf47a6b743f3763247f13c6335b3fc7b785baf7332f [root@localhost ~] # docker ps-a | grep mysql # confirm that the container is running ea1a8aa2d1f1 mysql:ljz "mysqld_safe" 41 seconds ago Up 40 seconds 0.0.0.0 docker ps 32770-> 3306/tcp mysql [root@localhost ~] # mysql-h 192.168.1.1 -u root-P 32770-p12345databases to test access to the database in the container If you cannot use the mysql command, execute "yum-y install mysql" to install Welcome to the MariaDB monitor. Commands end with; or\ g. # omit part of the content MySQL [(none)] > # command prompt changes, log in to the database MySQL [(none)] > show databases in the container # View database data +-+ | Database | +-+ | information_schema | | mysql | | test | +-+ 3 rows in set (0.00 sec) MySQL [ (none)] > exit # exit Bye
-this is the end of this article. Thank you for reading-
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.