Docker Compose一键搭建lnmp开发环境

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker Compose一键搭建lnmp开发环境相关的知识,希望对你有一定的参考价值。

参考技术A

docker compose 是用来配置和运行多容器服务的工具( 适用于单机,集群请使用k8s ),通过docker-compose命令可轻松对多个容器进行如下操作:

安装docker compose , 官方文档: https://docs.docker.com/compose/install/

执行docker compose准备步骤

docker compose的常用命令

docker compose 搭建lnmp开发环境

需要先进入php容器安装mysqli pdo等模块

Docker compose 一键部署LNMP平台

docker-compose.yml

version: ‘3‘
services:
  nginx:
    hostname: nginx
    build:
      context: ./nginx
      dockerfile: Dockerfile
    ports:
      - 80:80
    links:
      - php:php-cgi
    volumes:
      - ./wwwroot:/usr/local/nginx/html

  php:
    hostname: php
    build: ./php
    links:
      - mysql:mysql-db
    volumes:
      - ./wwwroot:/usr/local/nginx/html

  mysql:
    hostname: mysql
    image: mysql:5.6
    ports:
      - 3306:3306
    volumes:
      - ./mysql/conf:/etc/mysql/conf.d
      - ./mysql/data:/var/lib/mysql
    # command: --character-set-server=utf8
    environment:
      MYSQL_ROOT_PASSWORD: 123456
      MYSQL_DATABASE: wordpress
      MYSQL_USER: user
      MYSQL_PASSWORD: user123

nginx Dockerfile(配置文件和root目录都在当前路径下)

FROM centos:6
MAINTINER dengwenlong
RUN yum install -y gcc gcc-c++ make openssl-devel pcre-devel
ADD nginx-1.14.0.tar.gz /tmp
RUN cd /tmp/nginx-1.14.0.tar.gz && ./configure --prefix=/usr/local/nginx && make && makeinstall
COPY nginx.conf /usr/local/nginx/conf
EXPOSE 80
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]

mysql(使用docker pull mysql:5.6 镜像)

mkdir conf
mkdir data

php Dockerfile

FROM centos:6
MAINTAINER dengwenlong
RUN yum install -y gcc gcc-c++ gd-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel openssl-devel
ADD php-5.6.31.tar.gz /tmp/
RUN cd /tmp/php-5.6.31 &&     ./configure --prefix=/usr/local/php     --with-config-file-path=/usr/local/php/etc     --with-mysql --with-mysqli     --with-openssl --with-zlib --with-curl --with-gd     --with-jpeg-dir --with-png-dir --with-iconv     --enable-fpm --enable-zip --enable-mbstring &&     make -j 4 && make install &&     cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf &&     sed -i "s/127.0.0.1/0.0.0.0/" /usr/local/php/etc/php-fpm.conf &&     cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm &&     chmod +x /etc/init.d/php-fpm 
COPY php.ini /usr/local/php/etc
EXPOSE 9000
CMD /etc/init.d/php-fpm start && tail -F /var/log/messages

以上是关于Docker Compose一键搭建lnmp开发环境的主要内容,如果未能解决你的问题,请参考以下文章

Docker compose 一键部署LNMP平台

Linux下docker基础环境搭建

Docker环境下使用docker-compose一键式搭建RocketMQ(4.5.0版本)集群及其管理工具

docker-compose快速搭建lnmp+redis服务器环境

swarm docker-compose.yml NFS 搭建LNMP

dnmp一键部署搞定的php开发环境基于Docker的LNMP一键安装程序