参考:
一、简介
使用Dcoekr镜像部署lnmp(Linux、Nginx、MySQL、PHP7)。
1.1 结构
app└── src └── index.phpdocker-compose.yml etc└── localtimemysql├── conf│ └── my.cnf└── mysqldbnginx├── ca│ ├── server.crt│ └── server.key├── conf.d│ └── test.conf└── nginx.confphp-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:latestMAINTAINER bigbergRUN 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-develADD 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 wwwEXPOSE 9000CMD ["/usr/local/php/sbin/php-fpm", "--nodaemonize"]
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
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/tcpcomposelnmp_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