zoukankan      html  css  js  c++  java
  • docker-lnmp环境容器化搭建个人博客系统

    docker-容器化搭建个人博客系统

    1. 架构图

    2. 创建自定义网络

    2.1 创建自定义容器网络

    [root@docker php]# docker network create lnmp
    fef46378d1bcbbedde567a3f282a534b7fa155de79e5e20ccb7a53d2547173f5
    

    2.2 查看自定义网络是否创建成功

    [root@docker php]# docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    dca0690c5113        bridge              bridge              local
    870372883b51        host                host                local
    fef46378d1bc        lnmp                bridge              local
    38d5f2314b50        none                null                local
    fd51af6e7a9e        test                bridge              local
    

    3. 创建mysql容器

    [root@docker php]# docker run -d --name=lnmp_mysql --network=lnmp --mount src=mysql-vol,dst=/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=wordpress mysql:5.7 --character-set-server=utf8
    Unable to find image 'mysql:5.7' locally
    5.7: Pulling from library/mysql
    bb79b6b2107f: Pull complete 
    49e22f6fb9f7: Pull complete 
    842b1255668c: Pull complete 
    9f48d1f43000: Pull complete 
    c693f0615bce: Pull complete 
    8a621b9dbed2: Pull complete 
    0807d32aef13: Pull complete 
    6d2fc69dfa35: Pull complete 
    56153548dd2c: Pull complete 
    3bb6ba940303: Pull complete 
    3e1888da91a7: Pull complete 
    Digest: sha256:b3dc8d10307ab7b9ca1a7981b1601a67e176408be618fc4216d137be37dae10b
    Status: Downloaded newer image for mysql:5.7
    d1846141349adea311e4363452c748251b10b1aa6055963618ded9bd72d66a31
    

    4. 创建php容器

    [root@docker php]# docker run -d --name=lnmp_php --network=lnmp --mount type=bind,src=/var/www/html,dst=/var/www/html php:v1
    1057aa2bb5aec03ab37628a5dcf87957988481269b509fd88bd2ddd86bc07525
    

    5.创建nginx挂载目录

    • 创建一个站点目录

      [root@docker html]# mkdir -p /var/www/html
      
    • 创建nginx挂载配置文件目录

      [root@docker html]# mkdir -p /etc/nginx/
      
    • 编写nginx配置文件

      [root@docker nginx]# vim nginx.conf 
      [root@docker nginx]# cat nginx.conf 
      #user  nobody;
      worker_processes  1;
      
      #error_log  logs/error.log;
      #error_log  logs/error.log  notice;
      error_log  logs/error.log  info;
      
      pid        logs/nginx.pid;
      
      
      events {
          worker_connections  1024;
      }
      
      
      http {
          include       mime.types;
          default_type  application/octet-stream;
      
          log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                            '$status $body_bytes_sent "$http_referer" '
                            '"$http_user_agent" "$http_x_forwarded_for"';
      
          access_log  logs/access.log  main;
      
          sendfile        on;
      
          keepalive_timeout  65;
      
          gzip  on;
      
          server {
              listen       80;
              server_name  localhost;
      
              location / {
                  root   /var/www/html;
                  index  index.php index.html index.htm;
              }
              
              location ~ .php$ {
                  root           /var/www/html;
                  fastcgi_pass   lnmp_php:9000;      # 标签名,加端口
                  fastcgi_index  index.php;
                  fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                  include        fastcgi_params;
              }
      
          }
      
      
      }
      

    6. 创建nginx容器

    [root@docker nginx]# docker run -d --name lnmp_nginx --net lnmp -p 8080:80 --mount type=bind,src=/etc/nginx/nginx.conf,dst=/usr/local/nginx/conf/nginx.conf --mount type=bind,src=/var/www/html,dst=/var/www/html nginx:v1
    8cf455650e17a1c8459aca93af2874e8cce6882d5dab50b69659bd68c4639ad5
    

    7. 验证容器是否正常运行

    [root@docker nginx]# docker ps -a 
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
    8cf455650e17        nginx:v1            "nginx -g 'daemon of…"   9 minutes ago       Up 9 minutes        0.0.0.0:8080->80/tcp   lnmp_nginx
    330e1ee4149a        e797501fb114        "./sbin/php-fpm -c /…"   About an hour ago   Up 28 minutes       9000/tcp               lnmp_php
    d1846141349a        mysql:5.7           "docker-entrypoint.s…"   14 hours ago        Up 14 hours         3306/tcp, 33060/tcp    lnmp_mysql
    

    8. 浏览器访问测试

  • 相关阅读:
    HTTP协议详解
    如何编写出拥抱变化的代码
    Cookie ,Session
    Request 请求
    MySQL如何处理死锁
    如何优化冒泡排序
    java数据结构分析
    response响应
    Tomcat服务器
    HTTP协议
  • 原文地址:https://www.cnblogs.com/scajy/p/13820674.html
Copyright © 2011-2022 走看看