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

select the best presets to create full compatibility with all browsersselect

We know that the properties of the select tag in e...

Implementation of mysql data type conversion

1. Problem There is a table as shown below, we ne...

CSS flex several multi-column layout

Basic three-column layout .container{ display: fl...

SQL implementation of LeetCode (178. Score ranking)

[LeetCode] 178.Rank Scores Write a SQL query to r...

Linux sftp command usage

Concept of SFTP sftp is the abbreviation of Secur...

iframe adaptive size implementation code

Page domain relationship: The main page a.html bel...

Using JS to implement binary tree traversal algorithm example code

Table of contents Preface 1. Binary Tree 1.1. Tra...

This article helps you understand PReact10.5.13 source code

Table of contents render.js part create-context.j...

Practice of realizing Echarts chart width and height adaptation in Vue

Table of contents 1. Install and import 2. Define...

Encapsulate a simplest ErrorBoundary component to handle react exceptions

Preface Starting from React 16, the concept of Er...

Simple steps to write custom instructions in Vue3.0

Preface Vue provides a wealth of built-in directi...

How to create a simple column chart using Flex layout in css

The following is a bar chart using Flex layout: H...

Html Select option How to make the default selection

Adding the attribute selected = "selected&quo...

Solve the problem that ifconfig and addr cannot see the IP address in Linux

1. Install the Linux system on the virtual machin...