Use Docker to create a distributed lnmp image

Use Docker to create a distributed lnmp image

LNMP is a dynamic website server architecture built by combining Nginx, Mariadb and PHP under Linux system. Next, we use Docker to create a distributed lnmp image.

1. Docker distributed lnmp image production

1. Run Nginx, MySQL, and PHP containers

#Turn off the firewall and core protection systemctl disable firewalld
systemctl stop firewalld
setenforce 0

# Check whether ports 3306, 80, and 9000 are occupied ss -natp | grep 3306
ss -natp | grep 80
ss -natp | grep 9000

#Create a custom network docker network create -d bridge --subnet 172.168.184.0/24 --gateway 172.168.184.1 lnmp

#Run the Nginx container docker run -itd --name nginx --network lnmp -p 80:80 --ip 172.168.184.10 nginx:1.12.0

#Run the MySQL container docker run -itd --name mysql --network lnmp -p 3306:3306 --ip 172.168.184.20 -e MYSQL_ROOT_PASSWORD=010230 mysql:5.7

#Run the PHP container docker run -itd --name phpfpm --network lnmp -p 9000:9000 --ip 172.168.184.30 php:7.1-fpm 

insert image description here
insert image description here

insert image description here

2. Modify Nginx configuration file and PHP file

docker exec -it nginx /bin/bash
echo -e "server {
    listen 80;
    server_name localhost;
    location / {
        root /usr/share/nginx/html;
        index index.html index.htmi index.php;
    }
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }
    location ~ \.php$ {
        root /usr/share/nginx/html;
        fastcgi_pass 172.168.184.30:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include fastcgi_params;
    }
}" > /etc/nginx/conf.d/default.conf

nginx -s reload

docker exec -it phpfpm /bin/bash
mkdir -p /usr/share/nginx/html
echo "<?php
phpinfo();
?>" > /usr/share/nginx/html/index.php 

insert image description here

insert image description here

4. Conduct testing

Enter localhost/index.php in the virtual machine

insert image description here

Enter 192.168.184.70/index.php on this machine (my virtual machine address is 192.168.184.70)

insert image description here

The above is the details of using docker to create a distributed lnmp image. For more information about docker distributed lnmp images, please pay attention to other related articles on 123WORDPRESS.COM!

You may also be interested in:
  • How to quickly build an LNMP environment with Docker (latest)
  • How to deploy LNMP architecture in docker
  • How to build lnmp environment in docker
  • Use Docker to create an integrated service lnmp environment
  • Detailed explanation of using Docker to build LNMP environment
  • Example of compiling LNMP in Docker container

<<:  What does href=# mean in a link?

>>:  Detailed tutorial on installation and configuration of compressed version of MySQL database

Recommend

A detailed introduction to wget command in Linux

Table of contents First install wget View Help Ma...

Detailed explanation of mysql scheduled tasks (event events)

1. Brief introduction of the event An event is a ...

Detailed explanation of a method to rename procedure in MYSQL

Recently I have used the function of renaming sto...

How to Monitor Linux Memory Usage Using Bash Script

Preface There are many open source monitoring too...

JS+Canvas draws a lucky draw wheel

This article shares the specific code of JS+Canva...

Import CSS files using judgment conditions

Solution 1: Use conditional import in HTML docume...

CentOS 7.x docker uses overlay2 storage method

Edit /etc/docker/daemon.json and add the followin...

How to install Odoo12 development environment on Windows 10

Preface Since many friends say they don’t have Ma...

How to make a tar file of wsl through Docker

I've been playing with the remote development...

Continuous delivery using Jenkins and Docker under Docker

1. What is Continuous Delivery The software produ...

Quickly install MySQL5.7 compressed package on Windows

This article shares with you how to install the M...