Docker Compose部署lnmp

参考:https://github.com/micooz/docker-lnmp

一、简介

  使用Dcoekr镜像部署lnmp(Linux、Nginx、MySQL、PHP7)。

  1.1 结构     

app
└── src
    └── index.php
docker-compose.yml 
etc
└── localtime
mysql
├── conf
│   └── my.cnf
└── mysqldb
nginx
├── ca
│   ├── server.crt
│   └── server.key
├── conf.d
│   └── test.conf
└── nginx.conf
php-fpm
├── Dockerfile
├── php-7.2.3.tar.gz
├── php-fpm.conf
├── php.ini
├── var
│   ├── log
│   │   
│   └── run
│     
└── www.conf

# app 静态文件
# /etc/localtime 同步时区
# mysqldb 数据存储

  

二、部署

  2.1 php-fpm Dockerfile  

FROM centos:latest
MAINTAINER bigberg

RUN yum -y install gcc gcc-c++ gd-devel libxml2 libxml2-devel libcurl-devel \
    openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng  \
    freestyle freestyle-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
ADD php-7.2.3.tar.gz /tmp/
RUN cd /tmp/php-7.2.3 \
    && ./configure --prefix=/usr/local/php \
    --with-curl --with-freetype-dir --with-gd \
    --with-gettext --with-iconv-dir --with-kerberos \
    --with-libdir=lib64 --with-libxml-dir --with-mysqli \
    --with-openssl --with-pcre-regex --with-pdo-mysql \
    --with-pdo-sqlite --with-pear --with-png-dir \
    --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib \
    --with-bz2 --with-mhash --enable-fpm --enable-bcmath \
    --enable-libxml --enable-inline-optimization --enable-gd-native-ttf \
    --enable-mbregex --enable-mbstring --enable-opcache \
    --enable-pcntl --enable-shmop --enable-soap --enable-sockets \
    --enable-sysvsem --enable-sysvshm --enable-xml --enable-zip \
    && make && make install \
    && cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm \
    && chmod a+x /etc/init.d/php-fpm \
    && groupadd -g 1001 www \
    && useradd -g 1001 -u 1001 www

EXPOSE 9000
CMD ["/usr/local/php/sbin/php-fpm", "--nodaemonize"]
Dockerfile

  2.2 docker-compose.yml

version: '3'
services:
  # web server
  nginx:
    image: nginx:latest
    ports:
      - "80:80"
      - "443:443"
    volumes:
      # app,挂在目录
      - ./app/src:/usr/share/nginx/html
      # ngnix configs
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
      - ./nginx/conf.d/:/etc/nginx/conf.d/:ro
      # certificates
      - ./nginx/ca/server.crt/:/etc/nginx/server.crt:ro
      - ./nginx/ca/server.key/:/etc/nginx/server.key:ro
      - ./etc/localtime:/etc/localtime:ro
    links:
      - php:php-cgi

  # PHP-FPM
  php:
    build: ./php-fpm
    volumes:
      - ./app/src:/usr/share/nginx/html
      # php.ini
      - ./php-fpm/php.ini:/usr/local/php/etc/php.ini:ro
      - ./php-fpm/php-fpm.conf:/usr/local/php/etc/php-fpm.conf:ro
      - ./php-fpm/www.conf:/usr/local/php/etc/php-fpm.d/www.conf:ro
      - ./php-fpm/var:/usr/local/php/var
      - ./etc/localtime:/etc/localtime:ro
    links:
      - mysql:mysql
    ports:
      - "9000:9000"
    stdin_open: true
    tty: true

  # database
  mysql:
    image: mysql:latest
    ports:
      # Allow client to access 3306
      - "3306:3306"
    volumes:
      # my.cnf
      - ./mysql/conf/my.cnf:/etc/mysql/conf.d/my.cnf
      # your data will be stored in ./mysql
      - ./mysql/mysqldb:/var/lib/mysql
      - ./etc/localtime:/etc/localtime:ro
    environment:
      - MYSQL_ROOT_PASSWORD=123456
View Code

  2.3 构建  

$ docker-compose up --build

  2.4 查看

$ docker-compose ps
       Name                      Command               State                    Ports                  
-------------------------------------------------------------------------------------------------------
composelnmp_mysql_1   docker-entrypoint.sh mysqld      Up      0.0.0.0:3306->3306/tcp                  
composelnmp_nginx_1   nginx -g daemon off;             Up      0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
composelnmp_php_1     /usr/local/php/sbin/php-fp ...   Up      0.0.0.0:9000->9000/tcp

  相关文档:https://github.com/Bigberg/docker/tree/master/compose-lnmp

 

转载于:https://www.cnblogs.com/bigberg/p/8492197.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值