Docker 部署lnmp

**

第一步 下载安装docker 并且docker启动可以使用

**

拉取mysql镜像
[root@localhost ~]# docker pull mysql:5.7
[root@localhost ~]# docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --name scx_mysql mysql:5.7
46842d76e007b989dc585718a371554777aaf19f2a97fe495ac4f7d8bfef2636
查看MySQL镜像是否启动
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
46842d76e007        mysql:5.7           "docker-entrypoint.s…"   8 seconds ago       Up 7 seconds        0.0.0.0:3306->3306/tcp, 33060/tcp   scx_mysql
拉取php镜像
[root@localhost ~]# docker pull php:7.2-fpm
[root@localhost ~]# docker run -d -v /var/nginx/www/html:/var/www/html -p 9000:9000 --link scx_mysql --name scx_phpfpm php:7.2-fpm
664b08f2fe502eebd43d9213caf3a739a6b4f2572014178514dd548bb9bb210d
查看php镜像是否启动成功
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                               NAMES
664b08f2fe50        php:7.2-fpm         "docker-php-entrypoi…"   4 seconds ago        Up 2 seconds        0.0.0.0:9000->9000/tcp              scx_phpfpm
46842d76e007        mysql:5.7           "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:3306->3306/tcp, 33060/tcp   scx_mysql
进入容器中创建test.php文件在主机的/var/nginx/www/html下也会有一个同样的文件。
[root@localhost ~]# docker exec -it scx_phpfpm /bin/bash
root@664b08f2fe50:/var/www/html# touch test.php
root@664b08f2fe50:/var/www/html# ls
test.php
root@664b08f2fe50:/var/www/html# exit
exit
[root@localhost ~]# ls /var/nginx/www/html
test.php
拉取nginx镜像
[root@localhost ~]# docker pull nginx:1.12.2
启动nginx容器
[root@localhost ~]# docker run -d -p 80:80 --name scx_nginx -v /var/nginx/www/html/:/var/www/html --link scx_phpfpm:phpfpm --name scx_nginx nginx:1.12.2
c06b786197597c9a1323387c6cbc617e9de4364f81435110890d1aae73c2ac05
查看nginx容器是否启动成功
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES
c06b78619759        nginx:1.12.2        "nginx -g 'daemon of…"   4 seconds ago       Up 3 seconds        0.0.0.0:80->80/tcp                  scx_nginx
664b08f2fe50        php:7.2-fpm         "docker-php-entrypoi…"   4 minutes ago       Up 4 minutes        0.0.0.0:9000->9000/tcp              scx_phpfpm
46842d76e007        mysql:5.7           "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        0.0.0.0:3306->3306/tcp, 33060/tcp   scx_mysql
进入nginx容器到/etc/nginx/conf.d/下修改配置文件
[root@localhost ~]# docker exec -it scx_nginx /bin/bash
root@c06b78619759:/# cd /etc/nginx/conf.d/
root@c06b78619759:/etc/nginx/conf.d# apt-get update
root@c06b78619759:/etc/nginx/conf.d# apt-get install vim
修改配置文件中的php模块。
root@c06b78619759:/etc/nginx/conf.d# vim default.conf 
location ~ \.php$ {
        root           /var/www/html;
        fastcgi_pass   phpfpm:9000;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME   /var/www/html/$fastcgi_script_name;
        include        fastcgi_params;
    }
重新加载nginx    
root@c06b78619759:/etc/nginx/conf.d# nginx -s reload
root@c06b78619759:/etc/nginx/conf.d# exit
exit
在/var/nginx/www/html下创建
[root@localhost html]# vi index.php
<?php
  phpinfo();
 ?> 

下面测试就好了
Docker 部署lnmp_第1张图片

你可能感兴趣的:(Docker 部署lnmp)