Docker下部署lnmp详细步骤

目录
  • 拉取一个centos镜像
  • 基于centos生成nginx容器
  • 基于centos生成mysql容器
  • 基于centos生成php容器
  • 制作镜像
  • 用新镜像创建lnmp容器
  • 测试

拉取一个centos镜像

//下载centos镜像
[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@localhost ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED        SIZE
centos       latest    5d0da3dc9764   2 months ago   231MB

基于centos生成nginx容器

//使用镜像启动容器并进入容器
[root@localhost ~]# docker run -it --name centos_nginx centos /bin/bash
[root@c193fcb41eae /]# yum -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ vim which make wget
[root@c193fcb41eae /]# yum -y groups mark install 'Development Tools'

//创建用户和组
[root@c193fcb41eae /]# useradd -r -M -s /sbin/nologin nginx

//创建日志存放目录
[root@c193fcb41eae /]# mkdir -p /var/log/nginx
[root@c193fcb41eae /]# chown -R nginx.nginx /var/log/nginx

//下载安装包以及解压
[root@c193fcb41eae /]# cd /usr/src/
[root@c193fcb41eae src]# wget http://nginx.org/download/nginx-1.21.4.tar.gz
[root@c193fcb41eae src]# ls
debug  kernels  nginx-1.21.4.tar.gz
[root@c193fcb41eae src]# tar xf nginx-1.21.4.tar.gz 

//编译安装
[root@c193fcb41eae src]# cd nginx-1.21.4
[root@c193fcb41eae nginx-1.21.4]# ./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

[root@c193fcb41eae nginx-1.21.4]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install 

[root@c193fcb41eae nginx-1.21.4]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@c193fcb41eae nginx-1.21.4]# . /etc/profile.d/nginx.sh
[root@c193fcb41eae nginx-1.21.4]# which nginx
/usr/local/nginx/sbin/nginx

[root@localhost ~]# docker exec -it nginx05  /bin/bash
[root@c193fcb41eae /]# ss -antl
State      Recv-Q Send-Q                                        Local Address:Port                                                       Peer Address:Port
LISTEN     0      128                                                       *:80 

[root@c193fcb41eae /]# vi /usr/local/nginx/conf/nginx.conf
......
        location / {
            root   html;
            index index.php index.html index.htm;		#在45行中添加index.php
        }
......
        #取消location ~ .php$ 大括号前的注释(65~71)行
        location ~ \.php$ {
            root           /var/www/html;			#php测试页面目录
            fastcgi_pass   127.0.0.1:9000;			#在工作中这里要改为php服务器的地址
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;			#将/script改为$document_root
            include        fastcgi_params;
        }
        ......
daemon off;			#在前台运行

#下根目录下创建start.sh
[root@c193fcb41eae /]# cat >> start.sh <<EOF
#!/bin/bash
/usr/local/nginx/sbin/nginx
EOF

[ctrl]+q+p退出容器

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE              						 COMMAND               CREATED        STATUS          PORTS                   NAMES
c193fcb41eae   1314444/source_nginx:nginx-1.21.4         "/bin/bash"          24 hours ago    Up 30 minutes                           nginx05

基于centos生成mysql容器

//做mysql镜像并使用容器模式的网络
[root@localhost ~]# docker run -it --name mysql01 --network container:nginx05 centos:latest /bin/bash
[root@3367881fd446 /]#     #启动本地镜像centos 在里面安装MySQL --network container:nginx05 (以nginx05容器ID为共享网络)

//重新打开一个终端查看并上传mysql包
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS          PORTS                                   NAMES
466e7f22d1f3   centos:latest                       "/bin/bash"              11 seconds ago   Up 10 seconds                                           mysql01		# mysql容器正运行
c193fcb41eae   1314444/source_nginx:nginx-1.21.4   "/usr/local/nginx/sb…"   9 hours ago      Up 34 minutes   0.0.0.0:8080->80/tcp, :::8080->80/tcp   nginx05

# mysql容器正运行
在这里插入代码片[root@localhost ~]# ls
anaconda-ks.cfg  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz
[root@localhost ~]# docker cp mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz mysql01:/usr/src

//MySQL容器下查看
[root@c193fcb41eae /]# ls /usr/src/
debug  kernels  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

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

//清理环境以及安装依赖包
[root@c193fcb41eae /]# yum clean all
[root@c193fcb41eae /]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel ncurses-compat-libs which numactl libaio

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

//创建软连接
[root@c193fcb41eae src]# cd /usr/local/
[root@c193fcb41eae local]# ln -s mysql-5.7.34-linux-glibc2.12-x86_64 mysql
[root@c193fcb41eae local]# ls -l
total 0
drwxr-xr-x 2 root root   6 Nov  3  2020 bin
drwxr-xr-x 2 root root   6 Nov  3  2020 etc
drwxr-xr-x 2 root root   6 Nov  3  2020 games
drwxr-xr-x 2 root root   6 Nov  3  2020 include
drwxr-xr-x 2 root root   6 Nov  3  2020 lib
drwxr-xr-x 3 root root  17 Sep 15 14:17 lib64
drwxr-xr-x 2 root root   6 Nov  3  2020 libexec
lrwxrwxrwx 1 root root  35 Dec  3 16:18 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 9 root root 129 Dec  3 16:17 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@c193fcb41eae local]# chown -R mysql.mysql /usr/local/mysql*
[root@c193fcb41eae local]# ls -l
total 0
drwxr-xr-x 2 root  root    6 Nov  3  2020 bin
drwxr-xr-x 2 root  root    6 Nov  3  2020 etc
drwxr-xr-x 2 root  root    6 Nov  3  2020 games
drwxr-xr-x 2 root  root    6 Nov  3  2020 include
drwxr-xr-x 2 root  root    6 Nov  3  2020 lib
drwxr-xr-x 3 root  root   17 Sep 15 14:17 lib64
drwxr-xr-x 2 root  root    6 Nov  3  2020 libexec
lrwxrwxrwx 1 mysql mysql  35 Dec  3 16:18 mysql -> mysql-5.7.34-linux-glibc2.12-x86_64
drwxr-xr-x 9 mysql mysql 129 Dec  3 16:17 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@c193fcb41eae local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
[root@c193fcb41eae local]# source /etc/profile.d/mysql.sh
[root@c193fcb41eae local]# which mysql
/usr/local/mysql/bin/mysql

//头文件(include)、读取lib
[root@c193fcb41eae local]# ln -s /usr/local/mysql/include/ /usr/local/include/mysql
[root@c193fcb41eae local]# echo '/usr/local/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
[root@c193fcb41eae local]# ldconfig

//创建数据存放目录
[root@c193fcb41eae local]# mkdir -p /opt/data
[root@c193fcb41eae local]# chown -R mysql.mysql /opt/data/
[root@c193fcb41eae local]# ls -l /opt/data/
total 0

//初始化数据库
[root@c193fcb41eae local]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/opt/data
2021-12-03T16:29:44.502079Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-12-03T16:29:44.673278Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-12-03T16:29:44.703121Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-12-03T16:29:44.759550Z 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: 395770aa-5456-11ec-a2ae-0242ac110003.
2021-12-03T16:29:44.761730Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-12-03T16:29:45.276899Z 0 [Warning] CA certificate ca.pem is self signed.
2021-12-03T16:29:45.631478Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

//生成配置文件
[root@c193fcb41eae local]# cat > /etc/my.cnf <<EOF
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF

//修改
[root@c193fcb41eae local]# sed -ri 's#^(basedir=).*#\1/usr/local/mysql#g' /usr/local/mysql/support-files/mysql.server
[root@c193fcb41eae local]# sed -ri 's#^(datadir=).*#\1/opt/data#g' /usr/local/mysql/support-files/mysql.server
[root@c193fcb41eae 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@c193fcb41eae local]# /usr/local/mysql/support-files/mysql.server start
Starting MySQL.Logging to '/opt/data/c193fcb41eae.err'.
 SUCCESS!
[root@c193fcb41eae 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@c193fcb41eae 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> quit
Bye

//测试登录
[root@c193fcb41eae 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> quit
Bye

[root@c193fcb41eae src]# rm -rf mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz

在初始化mysql5.7的时候,报以下错误

error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory

//解决方法
yum -y install numactl libaio

基于centos生成php容器

//运行一个php容器和nginx共享网络
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS             PORTS                                   NAMES
466e7f22d1f3   centos:latest                       "/bin/bash"              52 minutes ago   Up 3 minutes                                               mysql01
c193fcb41eae   1314444/source_nginx:nginx-1.21.4   "/usr/local/nginx/sb…"   10 hours ago     Up About an hour   0.0.0.0:8080->80/tcp, :::8080->80/tcp   nginx05

[root@localhost ~]# docker run -it --name php8 --network container:nginx05 centos:latest  /bin/bash		# 启动本地镜像centos 在里面安装php --network container:nginx05 (以nginx05容器ID为共享网络)
[root@c193fcb41eae /]# 

//重新打开一个终端查看正在运行的容器
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS             PORTS                                   NAMES
22ce0738d9d7   centos:latest                       "/bin/bash"              28 seconds ago   Up 27 seconds                                              php8
466e7f22d1f3   centos:latest                       "/bin/bash"              54 minutes ago   Up 5 minutes                                               mysql01
c193fcb41eae   1314444/source_nginx:nginx-1.21.4   "/usr/local/nginx/sb…"   10 hours ago     Up About an hour   0.0.0.0:8080->80/tcp, :::8080->80/tcp   nginx05

//清理环境并安装epel源
[root@c193fcb41eae /]# yum clean all
[root@c193fcb41eae /]# yum -y install epel-release

//安装依赖包
[root@c193fcb41eae /]# 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 which --allowerasing

[root@c193fcb41eae /]# 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  mysql-5.7.34-linux-glibc2.12-x86_64.tar.gz  php-8.0.11.tar.gz
[root@localhost ~]# docker cp php-8.0.11.tar.gz 22ce0738d9d7:/usr/src/

//解压
[root@c193fcb41eae /]# ls /usr/src/
debug  kernels  php-8.0.11.tar.gz
[root@c193fcb41eae /]# cd /usr/src/
[root@c193fcb41eae src]# tar xf php-8.0.11.tar.gz -C /usr/local/
[root@c193fcb41eae src]# cd /usr/local/
[root@c193fcb41eae local]# ls
bin  etc  games  include  lib  lib64  libexec  php-8.0.11  sbin  share  src

//编译并安装
[root@c193fcb41eae local]# cd php-8.0.11/
[root@c193fcb41eae php-8.0.11]# ./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@c193fcb41eae php-8.0.11]# echo 'export PATH=/usr/local/php8/bin:$PATH' > /etc/profile.d/php.sh
[root@c193fcb41eae php-8.0.11]# source /etc/profile.d/php.sh
[root@c193fcb41eae php-8.0.11]# which php
/usr/local/php8/bin/php

//配置php-fpm文件
[root@c193fcb41eae php-8.0.11]# \cp php.ini-production /etc/php.ini
[root@c193fcb41eae php-8.0.11]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@c193fcb41eae php-8.0.11]# chmod +x /etc/init.d/php-fpm
[root@c193fcb41eae php-8.0.11]# cp /usr/local/php8/etc/php-fpm.conf.default /usr/local/php8/etc/php-fpm.conf
[root@c193fcb41eae php-8.0.11]# cp /usr/local/php8/etc/php-fpm.d/www.conf.default /usr/local/php8/etc/php-fpm.d/www.conf
[root@c193fcb41eae /]# mkdir -p /var/www/html
[root@c193fcb41eae /]#  cat > /var/www/html/index.php <<EOF
<?php
   phpinfo();
?>
EOF

[root@c193fcb41eae /]# vi /usr/local/php8/etc/php-fpm.conf
daemonize = no   #取消注释并设置daemonize = no,让php在前台运行

[root@c193fcb41eae /]# rm -rf /usr/src/php-8.0.11.tar.gz

[root@c193fcb41eae php-8.0.11]# /usr/local/php8/sbin/php-fpm
[root@c193fcb41eae php-8.0.11]# ss -anlt
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                              127.0.0.1:9000                            0.0.0.0:*
LISTEN            0                 80                                       *:3306                                  *:* 

//php启动脚本
[root@c193fcb41eae /]# vi /start.sh
#!/bin/bash
/usr/local/php8/sbin/php-fpm
[root@c193fcb41eae /]# chmod +x /start.sh 

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS          PORTS                                   NAMES
22ce0738d9d7   centos:latest                       "/bin/bash"              46 minutes ago   Up 46 minutes                                           php8
466e7f22d1f3   centos:latest                       "/bin/bash"              2 hours ago      Up 51 minutes                                           mysql01
c193fcb41eae   1314444/source_nginx:nginx-1.21.4   "/usr/local/nginx/sb…"   11 hours ago     Up 2 hours      0.0.0.0:8080->80/tcp, :::8080->80/tcp   nginx05

制作镜像

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                     COMMAND                  CREATED          STATUS             PORTS                                   NAMES
b8aff1ca0d45   centos:latest            "./start.sh"             4 seconds ago    Up 3 seconds                                               php8
cb81cdc671e4   centos:latest            "./start.sh"             8 minutes ago    Up 8 minutes                                               mysql01
c193fcb41eae   nginx:latest                       "/usr/local/nginx/sb…"   11 minutes ago   Up 11 minutes      0.0.0.0:8080->80/tcp, :::8080->80/tcp       nginx05

//制作nginx镜像
[root@localhost ~]# docker commit -a ' hhr 123@qq.com' -c 'CMD ["/usr/local/nginx/sbin/nginx"]' nginx05 1314444/lnmp:nginx-v0.1
sha256:ae3a6692a4c0c3a615bdf08ad2941a8526c0acda2b6b6b21dfb625407280ac25

//制作mysql镜像
[root@localhost ~]# docker commit -a ' hhr 123@qq.com' -c 'CMD ["./start.sh"]' mysql01 1314444/lnmp:mysql-v0.1
sha256:ff7d2b91b948baf5ecde42ad6783d80b00fb4c18bc3edc3e9d907f2a7b0e8b96

//制作php镜像
[root@localhost ~]# docker commit -a ' hhr 123@qq.com' -c 'CMD ["./start.sh"]' php8 1314444/lnmp:php8-v0.1
sha256:359cf3ac83b0faea8d17fa4ba7eb3ed149b4ab68b8f625ed20e049d73a2c78ee

[root@localhost ~]# docker images
REPOSITORY             TAG               IMAGE ID       CREATED         SIZE
1314444/lnmp           php8-v0.1         359cf3ac83b0   7 seconds ago   1.56GB
1314444/lnmp           mysql-v0.1        ff7d2b91b948   4 minutes ago   3.81GB
1314444/lnmp           nginx-v0.1        ae3a6692a4c0   7 minutes ago   551MB
centos                 latest            5d0da3dc9764   2 months ago    231MB

用新镜像创建lnmp容器

//启动nginx容器
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

[root@localhost ~]# docker run -d --name nginx -p 80:80 1314444/lnmp:nginx-v0.1
fad400d5145fea77e336200b915fd2321a9ee3c14d0bf8ecb9fe112f8e2b9106
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND         CREATED          STATUS         PORTS                               NAMES
a5346a4eb92b   ae3a6692a4c0   "./start.sh"    10 seconds ago   Up 9 seconds   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

[root@localhost ~]# docker exec -it nginx /bin/bash
[root@a5346a4eb92b /]# ss -anlt
State             Recv-Q            Send-Q                       Local Address:Port                       Peer Address:Port           Process
LISTEN            0                 128                                0.0.0.0:80                              0.0.0.0:* 

//启动mysql容器
[root@localhost ~]# docker run -d --name mysql --network container:fad400d5145f 1314444/lnmp:mysql-v0.1
cb81cdc671e4c266ea9d1537367ab509e1c50a9c29d6741fed632ee6c3ad1ddb

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE          COMMAND        CREATED          STATUS          PORTS                               NAMES
861eabb3a5b7   ff7d2b91b948   "./start.sh"   35 seconds ago   Up 34 seconds                                       mysql
a5346a4eb92b   ae3a6692a4c0   "./start.sh"   7 minutes ago    Up 7 minutes    0.0.0.0:80->80/tcp, :::80->80/tcp   nginx

[root@localhost ~]# docker exec -it mysql /bin/bash
[root@a5346a4eb92b /]# 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                *:*        

//启动php容器
[root@localhost ~]# docker run -d --name php --network container:fad400d5145f 1314444/lnmp:php-v0.1
b8aff1ca0d45033ed1f20071d98678573edec8c6c9c521fc7ddf024b01c0d0f9

[root@localhost ~]# docker ps
CONTAINER ID   IMAGE                               COMMAND                  CREATED          STATUS             PORTS                                   NAMES
b8aff1ca0d45   1314444/lnmp:php-v0.1              "./start.sh"             4 seconds ago    Up 3 seconds                                               php
cb81cdc671e4   1314444/lnmp:mysql-v0.1           "./start.sh"             8 minutes ago    Up 8 minutes                                               mysql
fad400d5145f   0229f7e8313f                        "./start.sh"             11 minutes ago   Up 11 minutes      0.0.0.0:80->80/tcp, :::80->80/tcp       nginx

[root@localhost ~]# docker exec -it php /bin/bash
[root@fad400d5145f /]# ss -anlt
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                                127.0.0.1:9000                              0.0.0.0:*
LISTEN             0                  80                                         *:3306                                    *:*

测试


到此这篇关于Docker下部署lnmp详细步骤的文章就介绍到这了,更多相关Docker部署lnmp内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • docker 搭建lnmp环境的方法步骤

    创建项目目录 mkdir php 创建如下项目结构 sites 目录放置项目文件 services 目录放置服务相关配置 script 放置自定义脚本 ├── Readme.md ├── docker-compose.yml ├── script ├── services │ ├── mariadb │ │ └── Dockerfile │ ├── nginx │ │ ├── Dockerfile │ │ ├── conf.d │ │ │ └── default.conf │ │ └── ngi

  • docker部署LNMP架构的方法

    环境要求: IP hostname 192.168.1.1 node1 项目规划: 容器网段:172.16.10.0/24 NGINX:172.16.10.10 MySQL:172.16.10.20 PHP:172.16.10.20 网站根目录:/www nginx配置文件:/conf mysql持久化目录:/var/lib/mysql 提前准备服务配置文件: nginx <strong>docker run -itd --name test nginx #运行test容器 docker cp

  • 详解使用 Docker 构建 LNMP 环境

    配置简单的 LNMP 环境 这里使用 docker-compose 的方式,配置内容如下: docker-compose.yml version: "2" services: # Nginx 1.11.10: https://hub.docker.com/_/nginx/ web: image: nginx:1.11.10 ports: # 将主机的 8080 端口映射到容器的 80 端口 - 8080:80 depends_on: - php # 同 php 一起共享 ./apps

  • Docker下部署lnmp详细步骤

    目录 拉取一个centos镜像 基于centos生成nginx容器 基于centos生成mysql容器 基于centos生成php容器 制作镜像 用新镜像创建lnmp容器 测试 拉取一个centos镜像 //下载centos镜像 [root@localhost ~]# docker pull centos Using default tag: latest latest: Pulling from library/centos a1d0c7532777: Pull complete Digest

  • Linux+Docker+SpringBoot+IDEA一键自动化部署的详细步骤

    Linux+Docker+SpringBoot+IDEA一键自动化部署的步骤 记录从打包到服务器配置上线全流程 安装docker 详细步骤请戳这里 用yum源安装用yum源安装 查看是否已安装docker列表 yum list installed | grep docke 安装docker yum -y install docker -y表示不询问安装,直到安装成功,安装完后再次查看安装列表 开放2375端口,开启远程访问 vim /usr/lib/systemd/system/docker.s

  • IDEA 集成 docker 实现远程部署的详细步骤

    1. docker 服务器开启远程访问 登录 docker 所在的远程服务器,使用命令 vim /usr/lib/systemd/system/docker.service 修改配置文件,需注意,修改时确认自己的账户拥有相应权限 主要操作是找到 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 这一行,注释掉,重新添加一行,在后面新增-H tcp://0.0.0.0:2375表示打开2

  • Intellij IDEA快速实现Docker镜像部署的方法步骤

    目录 1.Docker开启远程访问 2.Intellij IDEA安装Docker插件 3.spring boot服务Docker部署 4.创建Docker镜像 参考: 1.Docker开启远程访问 [root@izwz9eftauv7x69f5jvi96z docker]# vim /lib/systemd/system/docker.service #修改ExecStart这行 ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:

  • Docker安装mysql超详细步骤记录

    查看需要安装的镜像版本 dockerHub官网地址 1.搜索mysql 2.点击标签 3.点击Tags,查看想要的版本号 在安装好docker的linux中执行命令 拉取mysql最新版本 docker pull mysql 拉取mysql指定版本 docker pull mysql:5.7 拉取结束后,查看本地是否存在 docker images 运行mysql docker run -d -p 3306:3306 --name mysql -v /mysqldata/mysql/log:/v

  • centos7安装docker容器的超详细步骤记录

    目录 环境要求: 步骤如下: 一.删除之前安装的docker(若之前未安装过,此步骤省略…) 二.虚拟机联网,安装yum工具 三.设置docker镜像源 四.安装docker(网速慢的需要等会) 五.启动docker前准备** 六.启动docker 总结 环境要求: centos7.0以上版本(docker支持最低版本) 步骤如下: 一.删除之前安装的docker(若之前未安装过,此步骤省略…) 进入centos根目录执行以下命令(\ 是linux系统种命令换行符,如果命令过长,可以用\来换行)

  • SpringBoot之瘦身部署的详细步骤

    一.前言 SpringBoot部署起来虽然简单,如果服务器部署在公司内网,速度还行,但是如果部署在公网(阿里云等云服务器上),部署起来实在头疼: 编译出来的 Jar 包很大,如果工程引入了许多开源组件(SpringCloud等),那就更大了. 这个时候如果想要对线上运行工程有一些微调,则非常痛苦 二.瘦身前的Jar包 Tomcat在部署Web工程的时候,可以进行增量更新,SpringBoot也是可以的- SpringBoot编译出来的Jar包中,磁盘占用大的,是一些外部依赖库(jar包),例如:

  • IDEA中进行Docker项目部署的实现步骤

    现在大部分项目已经开始部署在Docker上面了,可是部署环节还是有点麻烦,所以本文想讲解一下如何使用IDEA一键部署. Docker配置 修改配置文件 打开Docker的配置文件: vim /usr/lib/systemd/system/docker.service 将下面这行注释掉: # ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock 新写一行: ExecStart=/usr/bi

  • kafka安装部署超详细步骤

    目录 概述 Step 1: 下载代码 Step 2: 启动服务 Step 3:创建一个主题 Step 4: 发送消息 Step 5: 消费消息 Step 6: 设置多个broker集群(单机伪集群的配置) Step 7: 测试集群的容错能力 7.1发布消息到集群 7.2消费消息 7.3干掉leader,测试集群容错 7.4再次消费消息,确认消息没有丢失 概述 Kafka是最初由Linkedin公司开发,是一个分布式.分区的.多副本的.多订阅者,基于zookeeper协调的分布式日志系统(也可以当

  • 使用docker安装elk的详细步骤

    目录 1.安装docker 2.下载elk 3.启动elk 3.启动elk 4.汉化 配置要求:一台Linux服务器,内存不少于2g,centos7以上系统 1.安装docker 安装教程:CentOS Docker 安装 | 菜鸟教程 分以下几个步骤(我只写我使用过的方式): curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 安装 Docker Engine-Community yum install -y y

随机推荐