• docker 部署lnmp


    目录

    1、部署nginx\

    1.1、vim Dockerfile

     1.2、

    1.3、vim nginx.conf

    2、部署mysql(容器IP 为 172.18.0.20)

    2.1、vim Dockerfile

    2.2、vim my.cnf

     2.3、

    3、部署php(容器IP 为 172.18.0.30)

    3.1、 vim Dockerfile

    3.2、

    3.3、

     3.4


     

    需要在完全干净的环境下进行

    1、部署nginx\

    1. mkdir /opt/nginx
    2. cd /opt/nginx/

     

     

    1. mkdir /opt/nginx/html
    2. tar zxvf wordpress-4.9.4-zh_CN.tar.gz -C /opt/nginx/html

    1.1、vim Dockerfile

    1. FROM centos:7
    2. MAINTAINER this is nginx image <wl>
    3. RUN yum -y install pcre-devel zlib-devel gcc gcc-c++ make
    4. RUN useradd -M -s /sbin/nologin nginx
    5. ADD nginx-1.12.0.tar.gz /usr/local/src/
    6. WORKDIR /usr/local/src/nginx-1.12.0
    7. RUN ./configure \
    8. --prefix=/usr/local/nginx \
    9. --user=nginx \
    10. --group=nginx \
    11. --with-http_stub_status_module && make && make install
    12. ENV PATH /usr/local/nginx/sbin:$PATH
    13. ADD nginx.conf /usr/local/nginx/conf/
    14. #ADD wordpress-4.9.4-zh_CN.tar.gz /usr/local/nginx/html/
    15. RUN chmod 777 -R /usr/local/nginx/html/
    16. EXPOSE 80
    17. EXPOSE 443
    18. ENTRYPOINT [ "/usr/local/nginx/sbin/nginx", "-g", "daemon off;" ]

     1.2、

    1. docker build -t nginx:lnmp .
    2. docker run -d --name nginx -p 80:80 -v /opt/nginx/html:/usr/local/nginx/html --net mynetwork --ip 172.18.0.10 nginx:lnmp

     

    1.3、vim nginx.conf

    2、部署mysql(容器IP 为 172.18.0.20)

    1. mkdir /opt/mysqld
    2. cd /opt/mysqld

    上传 mysql-boost-5.7.20.tar.gz 到 /opt/mysqld 目录中

    2.1、vim Dockerfile

    1. FROM centos:7
    2. MAINTAINER this is mysql image <wl>
    3. RUN yum -y install gcc gcc-c++ ncurses ncurses-devel bison cmake make
    4. ADD mysql-boost-5.7.20.tar.gz /usr/local/src/
    5. WORKDIR /usr/local/src/mysql-5.7.20/
    6. RUN cmake \
    7. -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
    8. -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
    9. -DSYSCONFDIR=/etc \
    10. -DSYSTEMD_PID_DIR=/usr/local/mysql \
    11. -DDEFAULT_CHARSET=utf8 \
    12. -DDEFAULT_COLLATION=utf8_general_ci \
    13. -DWITH_INNOBASE_STORAGE_ENGINE=1 \
    14. -DWITH_ARCHIVE_STORAGE_ENGINE=1 \
    15. -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
    16. -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
    17. -DMYSQL_DATADIR=/usr/local/mysql/data \
    18. -DWITH_BOOST=boost \
    19. -DWITH_SYSTEMD=1 && make && make install
    20. ADD my.cnf /etc/
    21. ENV PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH
    22. RUN useradd -M -s /sbin/nologin mysql
    23. RUN chown mysql:mysql /etc/my.cnf
    24. RUN chown -R mysql:mysql /usr/local/mysql/
    25. RUN /usr/local/mysql/bin/mysqld \
    26. --initialize-insecure \
    27. --user=mysql \
    28. --basedir=/usr/local/mysql \
    29. --datadir=/usr/local/mysql/data
    30. EXPOSE 3306
    31. CMD ["/usr/local/mysql/bin/mysqld"]


    2.2、vim my.cnf

    1. [client]
    2. port = 3306
    3. socket = /usr/local/mysql/mysql.sock
    4. [mysql]
    5. port = 3306
    6. socket = /usr/local/mysql/mysql.sock
    7. [mysqld]
    8. user = mysql
    9. basedir = /usr/local/mysql
    10. datadir = /usr/local/mysql/data
    11. port = 3306
    12. character_set_server=utf8
    13. pid-file = /usr/local/mysql/mysqld.pid
    14. socket = /usr/local/mysql/mysql.sock
    15. server-id = 1
    16. sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

     2.3、

    1. docker build -t mysql:lnmp .
    2. docker run --name=mysql -d --privileged -v /usr/local/mysql --net mynetwork --ip 172.18.0.20 mysql:lnmp

    3、部署php(容器IP 为 172.18.0.30)

    mkdir /opt/php
    cd /opt/php
     

    3.1、 vim Dockerfile

    1. FROM centos:7
    2. MAINTAINER this is php image <wl>
    3. RUN yum -y install gd \
    4. libjpeg libjpeg-devel \
    5. libpng libpng-devel \
    6. freetype freetype-devel \
    7. libxml2 libxml2-devel \
    8. zlib zlib-devel \
    9. curl curl-devel \
    10. openssl openssl-devel \
    11. gcc gcc-c++ make pcre-devel
    12. RUN useradd -M -s /sbin/nologin nginx
    13. ADD php-7.1.10.tar.bz2 /usr/local/src/
    14. WORKDIR /usr/local/src/php-7.1.10
    15. RUN ./configure \
    16. --prefix=/usr/local/php \
    17. --with-mysql-sock=/usr/local/mysql/mysql.sock \
    18. --with-mysqli \
    19. --with-zlib \
    20. --with-curl \
    21. --with-gd \
    22. --with-jpeg-dir \
    23. --with-png-dir \
    24. --with-freetype-dir \
    25. --with-openssl \
    26. --enable-fpm \
    27. --enable-mbstring \
    28. --enable-xml \
    29. --enable-session \
    30. --enable-ftp \
    31. --enable-pdo \
    32. --enable-tokenizer \
    33. --enable-zip && make && make install
    34. ENV PATH /usr/local/php/bin:/usr/local/php/sbin:$PATH
    35. ADD php.ini /usr/local/php/lib/
    36. ADD php-fpm.conf /usr/local/php/etc/
    37. ADD www.conf /usr/local/php/etc/php-fpm.d/
    38. EXPOSE 9000
    39. ENTRYPOINT [ "/usr/local/php/sbin/php-fpm", "-F" ]

    3.2、

    1. docker build -t php:lnmp .
    2. docker run --name=php -d -p 9000:9000 --volumes-from mysql --volumes-from nginx --net mynetwork --ip 172.18.0.30 php:lnmp

    3.3、

    1. docker exec -it mysql /bin/bash
    2. mysql
    3. create database wordpress;
    4. grant all privileges on wordpress.* to 'wordpress'@'%' identified by '123456';
    5. grant all privileges on *.* to 'root'@'%' identified by 'abc123';
    6. flush privileges;

     3.4

    进入之后把原来的删除

    这段文字粘贴到里面

  • 相关阅读:
    零基础自学javase黑马课程第九天数组练习
    交换机配置参考案例
    iOS Bug 收集
    【微服务】Day14(续 秒杀业务准备、消息队列)
    【正则】详解python正则表达式之re.group()用法
    [excel与dict] python 读取excel内容并放入字典、将字典内容写入 excel文件
    linux 用户不在sudoers文件中,此事将被报告
    【Javascript】构造函数的参数写法
    使用Docker创建并运行一个create-react-app应用(超简单)
    11 编译2022年最新的Linux kernel 6.1源码,并用QEMU模拟器运行
  • 原文地址:https://blog.csdn.net/Breeze_nebula/article/details/133697432