Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker's process of deploying LNMP and phpMyAdmin

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article focuses on "the process of deploying LNMP and phpMyAdmin in docker". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the process of docker deploying LNMP and phpMyAdmin".

Environmental preparation:

Deploy lnmp on a single host, based on multiple containers:

Nginx Service: 172.16.10.10

Mysql Service: 172.16.10.20

Php Service: 172.16.10.30

Resolve the problem of fixed ip address of container:

Note: because when the container stops or deletes the container and runs the same container again, its ip address is no longer the original address, so we need to customize a network segment to specify the ip address of the container.

Project actions:

(1) first customize a network:

[root@sqm-docker01] # docker network create-d bridge-- subnet 172.16.10.0 mynet1 24-- gateway 172.16.10.1

(2) download nginx,php:fpm,mysql-5.7 image:

[root@sqm-docker01 ~] # docker pull nginx [root@sqm-docker01 ~] # docker pull php:7.2-fpm [root@sqm-docker01 ~] # docker pull mysql:5.7

(3) # run a container based on nginx image #

# first run the nginx service to copy out the configuration file of nginx:

Parameter explanation:

Run: create a new container

-d: running in the background

-- name: custom name is test1

Create a directory on the host where files need to be mounted:

Home directory of the website: / wwwroot

Configuration file for nginx: / docker

[root@sqm-docker01 ~] # mkdir / wwwroot [root@sqm-docker01 ~] # mkdir / docker

# # use docker cp command to copy the directory where nginx stores configuration files to the local machine

Note: the docker cp command can copy the files on the host to the container or vice versa, copying the files or directories in the container to the local machine.

[root@sqm-docker01 ~] # docker cp test1:/etc/nginx / docker/ # use docker cp to copy the directory where nginx stores the configuration files to the host.

[root@sqm-docker01 ~] # ls / docker/nginx/conf.d/ default.conf

# Note: what needs to be modified is the default.conf file in the nginx conf.d directory, not the nginx.conf file.

Copy the nginx web page directory:

[root@sqm-docker01 ~] # docker cp test1:/usr/share/nginx/html / wwwroot/ [root@sqm-docker01 ~] # ls / wwwroot/html/50x.html index.html

Modify the default test page for nginx:

[root@sqm-docker01 html] # echo "hello welcome to nginx web" > index.html

(4) run the nginx container:

Mount the directory in the container to the local directory respectively, and specify the ip address

[root@sqm-docker01] # docker run-itd-- name nginx-- network my_net1-- ip 172.16.10.10-p 80:80-v / docker/nginx:/etc/nginx-v / wwwroot/html:/usr/share/nginx/html nginx:latest

Parameter explanation:

Run: run a container

-itd: I: interactive

T: pseudo terminal

D: keep the container running in the background

-- network: which network card is used to create a network?

-- ip: defines the ip address of the container

-v =-- volume data volume for a mount

Mounting format: host: in container

P: mapping port, host port: in-container port

(5) run the mysql container:

[root@sqm-docker01] # docker run-name mysql-e MYSQL_ROOT_PASSWORD=123.com-d-p 3306 MYSQL_ROOT_PASSWORD=123.com 3306-- network my_net1-- ip 172.16.10.20 mysql:5.7

-e is to set the environment variable in the container. We set the password environment variable of mysql. This variable will be passed into the container to set the password of mysql.

Test whether root users can log in to mysql locally:

First, you need to download the mysql client:

[root@sqm-docker01 ~] # yum-y install mysql

(6) run the php container:

[root@sqm-docker01] # docker run-itd-p 9000 name phpfpm-v / wwwroot/html:/usr/share/nginx/html-- network my_net1-- ip 172.16.10.30 php:7.2-fpm

Note:

Make sure that nginx and php share a directory where web pages are stored, and php creates the same default web page root directory as nginx (if it is not in the container when-v is mounted, it will be created automatically).

(7) configure nginx and php-fpm:

We want to configure the php parsing nginx:

Create a simple test page:

Next, you need to modify the nginx configuration file:

[root@sqm-docker01 html] # vim / docker/nginx/conf.d/default.conf

(8) configure mysql:

Set up phpMyadmin:

PhpMyAdmin is a database management tool based on PHP and constructed on the host of the website in the way of Web-Base, which allows managers to use Web interface to manage MySQL database. Through this Web interface, it can become a better way to input complicated SQL syntax in a simple way, especially to deal with the import and export of a large amount of data. One of the bigger advantages is that phpMyAdmin runs on the web server like other PHP programs, but you can use the HTML pages generated by these programs anywhere, that is, to remotely manage MySQL databases, and to easily create, modify, and delete databases and tables.

[root@sqm-docker01 html] # pwd/wwwroot/html

Extract to the current directory:

[root@sqm-docker01 html] # unzip phpMyAdmin-4.9.1-all-languages.zip

Rename:

[root@sqm-docker01 html] # mv phpMyAdmin-4.9.1-all-languages phpmyadmin

Modify the nginx configuration file-configure the connection to phpMyAdmin:

[root@sqm-docker01 html] # vim / docker/nginx/conf.d/default.conf

Copy the previous location configuration items and add the following two location configuration segments.

After modifying the nginx configuration file, restart nginx:

Visit the test page:

The port in the container has been mapped to the host, so access the host address directly: 172.16.1.30

Visit the php parsing nginx web page:

Next, test logging in to phpMyAdmin:

Visit url: http://172.16.1.30/phpmyadmin/index.php

The mysqli module is missing, so it cannot be accessed, so you need to add php to support mysql configuration module:

How to add an extension module for the container, we can log in to dockerhub to query the relevant documents:

Link path: https://hub.docker.com/

Copy the above dockerfile script and install it locally:

Note that you still need to add some content:

[root@sqm-docker01 ~] # vim Dockerfile

FROM php:7.2-fpmRUN apt-get update & & apt-get install-y\ libfreetype6-dev\ libjpeg62-turbo-dev\ libpng-dev\ & & docker-php-ext-install-j$ (nproc) iconv\ & & docker-php-ext-configure gd-- with-freetype-dir=/usr/include/-- with-jpeg-dir=/usr/include/\ & & docker-php-ext-install-j$ (nproc) Gd\ & & docker-php-ext-install mysqli pdo pdo_mysql

To build the dockerfile:

[root@sqm-docker01] # docker build-t phpfpm-mysqli.

Parameter explanation:

Build: build

-t: specify label

. Represents the Dockerfile under the current directory

After the construction is completed, delete the original php image and run the image that supports the mysqli module that has just been successfully built:

[root@sqm-docker01 ~] # docker stop phpfpm phpfpm [root@sqm-docker01 ~] # docker rm phpfpm phpfpm

[root@sqm-docker01] # docker run-- name phpfpm- d-p 9000-v / wwwroot/html:/usr/share/nginx/html-- network my_net1-- ip 172.16.10.30 phpfpm-mysqli:latest

# Image specifies the name of the image generated by the dockerfile you just built.

Modify the phpMyAdmin default sample (sample file):

If you want the configuration file to use it, you must rename it to remove the sample.

[root@sqm-docker01 phpmyadmin] # pwd/wwwroot/html/phpmyadmin [root@sqm-docker01 phpmyadmin] # cp config.sample.inc.php config.inc.php

Make changes to the configuration file:

[root@sqm-docker01 phpmyadmin] # vim config.inc.php

Restart php after modifying the configuration file:

[root@sqm-docker01 phpmyadmin] # docker restart phpfpm phpfpm

Visit the phpMyAdmin web page:

Enter url: http://172.16.1.30/phpmyadmin/index.php

# username and password, which is the login password of the database

Successfully accessed the mysql database.

At this point, I believe you have a deeper understanding of "the process of deploying LNMP and phpMyAdmin in docker". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report