docker 安装lnmp环境

2019-12-19  本文已影响0人  奋斗live

这里管理docker的安装不再描述,只简述lnmp环境的安装

一、安装nginx

1、安装 nginx最新镜像

docker pull nginx:latest    拉取最新 

2、查看

docker images

显示了nginx表示已安装了nginx镜像

3、创建主机目录
在主机中创建 /data/nginx/{conf,html,logs} 等目录
如下图


image.png

4、虚拟主机配置
在conf中创建nginx虚拟主机配置,如下

server {
    listen       80;
    server_name  www.docker.com;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;
    root   /usr/share/nginx/html/www.docker.com;
    location / {
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
       # root   /usr/share/nginx/html/www.docker.com;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        #root           html;
        fastcgi_pass   172.17.0.4:9000;
        fastcgi_index  index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

5、创建容器,并进行主机和docker容器之间的挂载
挂载资源目录、配置目录和日志

docker run -d -p 80:80 --name nginx -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf:/etc/nginx/conf.d -v /data/nginx/logs:/var/log/nginx nginx

6、重启nginx容器

docker restart nginx

7、测试访问
如下,表示成功


image.png
一、安装php

1、拉取php镜像

docker pull php:7.0-fpm

查看镜像如下


image.png

2、创建php容器,并进行挂载

docker run -d -p 9000:9000 --name php7 -v /data/nginx/html:/usr/share/nginx/html docker.io/phpdockerio/php7-fpm

3、测试访问
如下


image.png
三、安装mysql

1、拉取mysq镜像和查看

docker pull mysql:5.7
docker images
image.png

2、创建容器,并挂载

docker run -p 3306:3306 --name mysql -v /data/mysql/conf:/etc/mysql/conf.d -v /data/mysql/logs:/logs -v /data/mysql/data:/mysql_data -e MYSQL_ROOT_PASSWORD=123abc -d docker.io/centos/mysql-57-centos7

3、修改账号密码

docker exec -it mysql bash

登陆到mysql中

set password for 'root'@'localhost'=password('111');
上一篇 下一篇

猜你喜欢

热点阅读