IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 系统运维 -> dockr容器lnmp -> 正文阅读

[系统运维]dockr容器lnmp

dockr容器lnmp

nginx

[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
a1d0c7532777: Pull complete 
Digest: sha256:a27fd8080b517143cbbbab9dfb7c8571c40d67d534bbdee55bd6c473f432b177
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

[root@829947547f38 /]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget
[root@829947547f38 /]# yum -y group mark install "Development Tools"
Last metadata expiration check: 0:02:03 ago on Thu 02 Dec 2021 08:29:33 AM UTC.
Dependencies resolved.
==================================================================================
 Package            Architecture      Version            Repository          Size
==================================================================================
Installing Groups:
 Development Tools                                                               

Transaction Summary
==================================================================================

Complete!

[root@829947547f38 /]# useradd -r -M -s /sbin/nologin nginx

[root@829947547f38 ~]# mkdir -p /var/log/nginx

[root@829947547f38 local]# wget http://nginx.org/download/nginx-1.20.1.tar.gz
--2021-12-02 08:33:59--  http://nginx.org/download/nginx-1.20.1.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1061461 (1.0M) [application/octet-stream]
Saving to: ‘nginx-1.20.1.tar.gz’

nginx-1.20.1.tar.gz  100%[====================>]   1.01M   224KB/s    in 4.6s    

2021-12-02 08:34:04 (224 KB/s) - ‘nginx-1.20.1.tar.gz’ saved [1061461/1061461]
[root@829947547f38 local]# ls
bin  games    lib    libexec              sbin   src
etc  include  lib64  nginx-1.20.1.tar.gz  share
[root@829947547f38 local]# tar xf nginx-1.20.1.tar.gz  
[root@829947547f38 local]# ls
bin  games    lib    libexec       nginx-1.20.1.tar.gz  share
etc  include  lib64  nginx-1.20.1  sbin                 src

[root@829947547f38 local]# cd nginx-1.20.1
[root@829947547f38 nginx-1.20.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
checking for OS
 + Linux 4.18.0-257.el8.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 8.5.0 20210514 (Red Hat 8.5.0-4) (GCC) 
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
checking for gcc builtin atomic operations ... found
checking for C99 variadic macros ... found
[root@829947547f38 nginx-1.20.1]# make && make install

[root@829947547f38 nginx-1.20.1]# echo "export PATH=/usr/local/nginx/sbin:$PATH" > /etc/profile.d/nginx.sh

[root@829947547f38 local]# /usr/local/nginx/sbin/nginx 
[root@829947547f38 local]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process   
LISTEN   0        128              0.0.0.0:80            0.0.0.0:* 

在创建镜像时,我们不能关闭容器,必须使其处于运行状态,所以我们必须要另起一个终端,然后执行

[root@localhost ~]# docker commit -p c1
sha256:4b2af8fdacc7b0046922b715eb4a5b3b4098e8bcf77046c78c59cb2e17249d99
[root@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
<none>       <none>    4b2af8fdacc7   28 seconds ago   550MB
busybox      latest    d23834f29b38   2 days ago       1.24MB
httpd        latest    ad17c88403e2   13 days ago      143MB
centos       latest    5d0da3dc9764   2 months ago     231MB
[root@localhost ~]# docker tag 4b2af8fdacc7 best2001/c1:v0.1
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
best2001/c1   v0.1      4b2af8fdacc7   2 minutes ago   550MB
busybox       latest    d23834f29b38   2 days ago      1.24MB
httpd         latest    ad17c88403e2   13 days ago     143MB
centos        latest    5d0da3dc9764   2 months ago    231MB

使用新生成的镜像创建容器

[root@localhost ~]# docker run --name t1 -it best2001/c1:v0.1
[root@49676d942358 /]# ls
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr
[root@49676d942358 /]# /usr/local/nginx/sbin/nginx 
[root@49676d942358 /]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port     Peer Address:Port   Process   
LISTEN   0        128              0.0.0.0:80            0.0.0.0:*  

由此可见,新生成的镜像中是包含了新增的内容的,但是此时有一个问题,那就是容器默认要启动的进程是什么?在这里,默认情况下是启动的sh进程,但我们是要启动一个http站点,所以我们要在创建镜像时将容器默认启动的进程设为httpd,这样一来我们就可以通过新生成的镜像来快速构建一个简单的http站点了。

使用命令查看b1容器启动的默认进程是什么docker inspect

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE              COMMAND       CREATED         STATUS         PORTS     NAMES
49676d942358   best2001/c1:v0.1   "/bin/bash"   7 minutes ago   Up 7 minutes             t1
[root@localhost ~]# docker inspect 49676d942358
·····省略部分·····
                    "EndpointID": "3add13e115a71559c4392b6aa02d284ec27dce733909d1d3dd63d02b053cea24",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:03",
                    "DriverOpts": null
                }
            }
        }
    }
]

使用镜像创建容器

[root@localhost ~]# docker run --name n3 -p 80:80 -dt best2001/c1:v0.1 
2651ba6d2d5fd1e3eba909440e792142dbd0ae7d4ccf8e45d264ce82109f5e70

[root@localhost ~]# docker container ls
CONTAINER ID   IMAGE              COMMAND       CREATED              STATUS              PORTS     NAMES
2651ba6d2d5f   best2001/c1:v0.1   "/bin/bash"   About a minute ago   Up About a minute             n3


访问测试nginx

[root@localhost ~]# docker container ls
CONTAINER ID   IMAGE              COMMAND       CREATED         STATUS         PORTS     NAMES
2651ba6d2d5f   best2001/c1:v0.1   "/bin/bash"   3 minutes ago   Up 3 minutes             n3
[root@localhost ~]# curl 172.17.0.2
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

mysql

做mysql镜像并使用容器模式的网络

[root@localhost ~]# docker run -it --name mysql01 --network container:2651ba6d2d5f centos:latest /bin/bash
[root@3367881fd446 /]#     # 启动本地镜像centos 在里面安装MySQL --network container:3367881fd446(以nginx容器ID为共享网络)

重新打开一个终端查看

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE              COMMAND              CREATED          STATUS          PORTS     NAMES
2102e9a88ce8   centos:latest      "/bin/bash"          34 seconds ago   Up 33 seconds             mysql01  # mysql容器正在运行
2651ba6d2d5f   yunjisuanlp/nginx:v1   "/usr/local/nginx/sb…"   13 minutes ago   Up 13 minutes             confident_wing

上传MySQL包到本地上传到centos容器

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND      CREATED         STATUS         PORTS   NAMES
2102e9a88ce8   centos:latest  "/bin/bash"  34 seconds ago  Up 33 seconds          mysql01  # mysql容器正运行
2651ba6d2d5f   yunjisuanlp/nginx:v1   "/usr/local/nginx/sb…"   13 minutes ago   Up 13 minutes             confident_wing

[root@localhost ~]# cd /usr/src/
[root@localhost src]# ls
debug  kernels  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

[root@localhost src]# docker cp mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz 2102e9a88ce8:/usr/src # cp到mysql01容器ID下的/usr/src

MySQL容器下查看

[root@3367881fd446 ~]# cd /usr/src
[root@3367881fd446 src]# ls
debug  kernels  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

# 下载
yum clean all # 清理缓存
yum makecache # 生成新缓存
yum -y install which numactl-libs ncurses-compat-libs # 安装

# 创建用户
[root@3367881fd446 src]# useradd -r -M -s /sbin/nologin mysql
[root@3367881fd446 src]# id mysql
uid=998(mysql) gid=996(mysql) groups=996(mysql)

# 解压MySQL包
[root@3367881fd446 src]# tar xf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[root@3367881fd446 src]# cd /usr/local/
[root@3367881fd446 local]# ls
bin  games    lib    libexec                              sbin   src
etc  include  lib64  mysql-5.7.34-linux-glibc2.12-x86_64  share

# 创建软连接并修改属主属组
[root@3367881fd446 local]# ln -sv mysql-5.7.34-linux-glibc2.12-x86_64 mysql
'mysql' -> 'mysql-5.7.34-linux-glibc2.12-x86_64'

[root@3367881fd446 local]# ls -l
total 0
………………
lrwxrwxrwx 1 root root  35 Dec  3 08:24 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 129 Dec  3 08:21 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 2 root root   6 Nov  3  2020 sbin
drwxr-xr-x 5 root root  49 Sep 15 14:17 share
drwxr-xr-x 2 root root   6 Nov  3  2020 src

[root@3367881fd446 local]# chown -R mysql.mysql mysql*
[root@3367881fd446 local]# ls -l
total 0
……………………
lrwxrwxrwx 1 mysql mysql  35 Dec  3 08:24 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 9 mysql mysql 129 Dec  3 08:21 mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 2 root  root    6 Nov  3  2020 sbin
drwxr-xr-x 5 root  root   49 Sep 15 14:17 share
drwxr-xr-x 2 root  root    6 Nov  3  2020 src

# 添加环境变量
[root@3367881fd446 local]# echo "export PATH=/usr/local/mysql/bin:$PATH" > /etc/profile.d/mysql.sh
[root@3367881fd446 local]# bash
[root@3367881fd446 bin]# which mysql
/usr/local/mysql/bin/mysql

# 创建数据存放目录
[root@3367881fd446 local]# mkdir /opt/data
[root@3367881fd446 local]# ls -l /opt
total 0
drwxr-xr-x 2 root root 6 Dec  3 08:29 data

[root@3367881fd446 local]# chown -R mysql.mysql /opt/data
[root@3367881fd446 local]# ls -l /opt
total 0
drwxr-xr-x 2 mysql mysql 6 Dec  3 08:29 data

# 初始哈数据库不要密码
[root@3367881fd446 local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data
2021-12-03T08:42:57.345198Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-12-03T08:42:57.466893Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-12-03T08:42:57.489097Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-12-03T08:42:57.542400Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 03bd41c9-5415-11ec-ae6b-0242ac110002.
2021-12-03T08:42:57.543336Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-12-03T08:42:58.297624Z 0 [Warning] CA certificate ca.pem is self signed.
2021-12-03T08:42:58.547329Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.


# 生成配置文件
[root@3367881fd446 local]# vi /etc/my.cnf
[mysqld]
port = 3306
datadir = /opt/data
basedir = /usr/local/mysql
socket = /tmp/mysql.sock
pid-file = /opt/data/mysql.pid
log-error = /opt/data/mysql.err
skip-name-resolve

# 修改文件
[root@3367881fd446 local]# vi /usr/local/mysql/support-files/mysql.server
……………………
basedir=/usr/local/mysql
datadir=/opt/data
……………………

# 启动
[root@3367881fd446 local]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128              0.0.0.0:80              0.0.0.0:*                
[root@3367881fd446 local]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/mysql.err'.
 SUCCESS! 
[root@3367881fd446 local]# ss -antl
State    Recv-Q   Send-Q     Local Address:Port       Peer Address:Port   Process   
LISTEN   0        128              0.0.0.0:80              0.0.0.0:*                
LISTEN   0        80                     *:3306                  *:*                
# 登录设置密码
[root@3367881fd446 local]# mysql      
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> set password = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> exit
Bye
[root@3367881fd446 local]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> exit
Bye

将MySQL提交为一个镜像

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE             COMMAND        CREATED             STATUS          PORTS  NAMES
2102e9a88ce8  centos:latest     "/bin/bash"    About an hour ago   Up 42 minutes          mysql01
2651ba6d2d5f  yunjisuanlp/nginx:v1 "/usr/local/nginx/sb…" About an hour ago   Up About an hour             confident_wing

[root@localhost ~]# docker commit -p mysql01 # 暂停mysql01

[root@localhost ~]# docker images
REPOSITORY          TAG       IMAGE ID       CREATED         SIZE
<none>              <none>    77281e1fab7e   3 seconds ago   3.78GB  # 新提交的镜像
yunjisuanlp/nginx   v1        ac3319cbbafb   19 hours ago    550MB
centos              latest    5d0da3dc9764   2 months ago    231MB

[root@localhost ~]# docker tag 77281e1fab7e best2001/mysql:v2  # 起名

[root@localhost ~]# docker images
REPOSITORY         TAG       IMAGE ID       CREATED          SIZE
best2001/nginx     v0.3      148fe5cb817d   32 minutes ago   569MB
best2001/mysql   v2        77281e1fab7e   About a minute ago   3.78GB # 成功
best2001/nginx     v0.2      943ccc9a6b39   8 hours ago      550MB
best2001/c1        v0.1      4b2af8fdacc7   30 hours ago     550MB
busybox            latest    d23834f29b38   3 days ago       1.24MB
centos             latest    5d0da3dc9764   2 months ago     231MB

php

# 运行一个php容器和nginx共享网络
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED             STATUS          PORTS     NAMES
efba8ef79d7c   centos                "/bin/bash"              5 hours ago         Up 5 hours                mysql
480184a1fb6a   best2001/nginx:v0.2   "/usr/local/nginx/sb…"   5 hours ago         Up 54 minutes             nginx


[root@localhost ~]# docker run -it --name php8 --network container:3367881fd446(nginxID) centos:latest /bin/bash
[root@3367881fd446 /]#

# 重新打开一个终端查看正在运行的容器
[root@localhost ~]# docker ps 
CONTAINER ID   IMAGE                  COMMAND                  CREATED              STATUS              PORTS     NAMES
3f482b46f4f0   centos:latest          "/bin/bash"              About a minute ago   Up About a minute             php8
2102e9a88ce8   centos:latest          "/bin/bash"              About an hour ago    Up 55 minutes                 mysql01
2651ba6d2d5f   yunjisuanlp/nginx:v1   "/usr/local/nginx/sb…"   2 hours ago          Up 2 hours                    confident_wing

回到php启动的终端

[root@d0324df0d8b5 /]# yum clean all
[root@d0324df0d8b5 /]# yum makecache
[root@d0324df0d8b5 /]# yum -y install epel-release # 下载依托源

# 下载依赖包
yum install sqlite-devel libzip-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel  libjpeg-turbo libjpeg-turbo-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel gcc gcc-c++ make --allowerasing

yum -y install http://mirror.centos.org/centos/8/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm

# 打开另一个终端上传php包到容器内
[root@localhost ~]# ls
anaconda-ks.cfg  nginx.tar.gz  php-8.0.10.tar.gz
[root@localhost ~]# docker cp php-8.0.10.tar.gz 3f482b46f4f0:/usr/src

# 回到容器终端查看并解压
[root@d0324df0d8b5 /]# cd /usr/src
[root@d0324df0d8b5 src]# ls
debug  kernels  php-8.0.10.tar.gz

[root@d0324df0d8b5 src]# tar xf php-8.0.10.tar.gz -C /usr/local/
[root@d0324df0d8b5 src]# cd /usr/local/
[root@d0324df0d8b5 local]# ls
bin  etc  games  include  lib  lib64  libexec  php-8.0.10  sbin  share  src

# 编译安装

[root@d0324df0d8b5 ]# cd php-8.0.10/
[root@d0324df0d8b5 php-8.0.10]# ./configure --prefix=/usr/local/php8  \
--with-config-file-path=/etc \
--enable-fpm \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
.......

# 安装
make && make install
......

# 添加环境变量
[root@d0324df0d8b5 php-8.0.10]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@d0324df0d8b5 php-8.0.10]# bash

# 配置php-fpm
[root@d0324df0d8b5 php-8.0.10]# cp php.ini-production /etc/php.ini
[root@d0324df0d8b5 php-8.0.10]# cd sapi/fpm/
[root@d0324df0d8b5 fpm]# ls
config.m4  init.d.php-fpm     Makefile.frag  php-fpm.8.in     php-fpm.service     status.html.in  www.conf.in
CREDITS    init.d.php-fpm.in  php-fpm        php-fpm.conf     php-fpm.service.in  tests
fpm        LICENSE            php-fpm.8      php-fpm.conf.in  status.html         www.conf
[root@d0324df0d8b5 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
[root@d0324df0d8b5 fpm]# chmod +x /etc/init.d/php-fpm
[root@d0324df0d8b5 fpm]# cd /usr/local/php8/etc/
[root@d0324df0d8b5 etc]# cp php-fpm.conf.default php-fpm.conf
[root@d0324df0d8b5 etc]# cd php-fpm.d/
[root@d0324df0d8b5 php-fpm.d]# cp www.conf.default www.conf

# 创建php文件
[root@d0324df0d8b5 ~]# cat /var/www/html/index.php 
<?php
        phpinfo();
?>

# 启动php

[root@d0324df0d8b5 php-fpm.d]# /usr/local/php8/sbin/php-fpm -c /usr/local/php8/etc/php-fpm.conf
[root@d0324df0d8b5 etc]# ss -antl
State          Recv-Q          Send-Q                   Local Address:Port                   Peer Address:Port         Process         
LISTEN         0               128                          127.0.0.1:9000                        0.0.0.0:*                            
LISTEN         0               128                            0.0.0.0:80                          0.0.0.0:*                            
LISTEN         0               80                                   *:3306                              *:*

配置nginx

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED             STATUS          PORTS     NAMES
d0324df0d8b5   yunjisuanlp/php8:v1   "/bin/bash"              About an hour ago   Up 52 minutes             php1
480184a1fb6a   best2001/nginx:v0.2   "/usr/local/nginx/sb…"   5 hours ago         Up 54 minutes             nginx
2102e9a88ce8   centos:latest          "/bin/bash"              2 hours ago      Up 2 hours                mysql01
[root@localhost ~]# docker exec -it 480184a1fb6a /bin/bash
[root@480184a1fb6a /]# cd /usr/local/nginx/conf/
[root@480184a1fb6a conf]# vi nginx.conf
..........
        location / {
            root   html;
            index  index.php index.html index.htm; # 添加index.php
        }
.........
location ~ \.php$ {
            root           /var/www/html;   #设置php的index.php的地址
            fastcgi_pass   127.0.0.1:9000;   #修改ip
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $Document_root$fastcgi_script_name; # 修改
            include        fastcgi_params;
        }
........        

[root@480184a1fb6a local]# nginx -s reload

运行并访问php测试页面

[root@localhost ~]# docker run --name nginx01 -d -p 80:80 best2001/nginx:v0.3
b5ff13385f02e92585d3e37676534ce781616c9e679dd8b06a7c93ac11e45aa8
[root@localhost ~]# ss -antl
State                 Recv-Q                Send-Q                                Local Address:Port                                 Peer Address:Port                Process                
LISTEN                0                     128                                         0.0.0.0:80                                        0.0.0.0:*                                          
LISTEN                0                     128                                         0.0.0.0:22                                        0.0.0.0:*                                          
LISTEN                0                     128                                            [::]:80                                           [::]:*                                          
LISTEN                0                     32                                                *:21                                              *:*                                          
LISTEN                0                     128                                            [::]:22                                           [::]:*      
[root@localhost ~]# docker run -d --name php --network container:nginx01 best2001/php:v3 
16566e5f7f9f142dd1852fecb68cc6b44dfdb4225b4b10674bebde0bde9b832d
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED         STATUS         PORTS                               NAMES
16566e5f7f9f   best2001/php:v3       "/usr/local/php8/sbi…"   2 seconds ago   Up 1 second                                        php
b5ff13385f02   best2001/nginx:v0.3   "/usr/local/nginx/sb…"   5 minutes ago   Up 5 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx01

在这里插入图片描述

  系统运维 最新文章
配置小型公司网络WLAN基本业务(AC通过三层
如何在交付运维过程中建立风险底线意识,提
快速传输大文件,怎么通过网络传大文件给对
从游戏服务端角度分析移动同步(状态同步)
MySQL使用MyCat实现分库分表
如何用DWDM射频光纤技术实现200公里外的站点
国内顺畅下载k8s.gcr.io的镜像
自动化测试appium
ctfshow ssrf
Linux操作系统学习之实用指令(Centos7/8均
上一篇文章      下一篇文章      查看所有文章
加:2021-12-04 13:48:55  更:2021-12-04 13:49:42 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/16 2:43:37-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码