docker-compose创建lnmp环境

version: "3.8"
services:
  nginx:
    container_name: "nginx"
    image: nginx:latest
    #重启策略:
    #no,默认策略,在容器退出时,不重启容器;
    #on-failure,在容器非正常退出时(退出状态非0),才会重启容器
    #on-failure:3,在容器非正常退出时重启容器,最多重启3次
    #always,在容器退出时,总是重启容器
    #unless-stopped,在容器退出时总是重启容器,但是不考虑在Docker守护进程启动时就已经停止了的容器
    #端口映射(宿主机8080->nginx容器80,可以映射多个,比如443端口)
    ports:
      - "80:80"
      - "443:443"
    environment:
      - TZ=Asia/Shanghai
    #数据卷挂载
    volumes:
      - "/usr/local/nginx/conf.d:/etc/nginx/conf.d"
      - "/usr/local/nginx/nginx.conf:/etc/nginx/nginx.conf"
      - "/usr/local/nginx/log:/var/log/nginx"
      - "/usr/local/nginx/html:/usr/share/nginx/html"

  php:
    container_name: "php7.3"
#    注意,在version 1里同时使用image和build是不允许的,version 2则可以,如果同时指定了两者,会将build出来的镜像打上名为image标签。
    build: ./php-extension
    image: php7.3-app
    ports:
      - "9000:9000"
    volumes:
      - "/home/www/phpProject:/var/www/html"
      - "/usr/local/php7.3/etc:/usr/local/etc"
      - "/usr/local/php7.3/log/:/var/log/php/"
    stdin_open: true
    tty: true
    #links:
    #      - "mysql"
    # 设置时区
    environment:
      - TZ=Asia/Shanghai
  mysql:
    container_name: "mysql8"
    image: mysql:8
    #mysql的端口
    ports:
      - "3306:3306"
    #数据卷挂载设置
    volumes:
      - "/usr/local/mysql8/data:/var/lib/mysql"
      - "/usr/local/mysql8/etc:/etc/mysql"
      - "/usr/local/mysql8/logs:/data/mysql/logs"
    environment:
      - TZ=Asia/Shanghai # 设置时区
      #设置mysql的密码
      - MYSQL_ROOT_PASSWORD=123456

  redis:
    container_name: "redis"
    image: redis
    ports:
      - "6379:6379"
    volumes:
      - "/usr/local/redis/etc:/usr/local/etc/redis"
      - "/usr/local/redis/data:/data"
    command:
      #执行命令(设置密码和持久化)
     redis-server /usr/local/etc/redis/redis.conf --requirepass 123456 --appendonly yes
     # redis-server /usr/local/etc/redis/redis.conf
    environment:
      - TZ=Asia/Shanghai # 设置时区

networks:
  default:
      name: mynet

在根目录下创建./php-extension/Dockerfile

FROM php:7.3-fpm

# 安装 php 扩展
RUN sed -i "s@http://deb.debian.org@http://mirrors.aliyun.com@g" /etc/apt/sources.list && rm -Rf /var/lib/apt/lists/* &&  cat /etc/apt/sources.list
RUN apt-get update -y
RUN docker-php-ext-install -j$(nproc) mysqli pdo_mysql shmop iconv sockets calendar

RUN apt-get install -y --no-install-recommends libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    && rm -r /var/lib/apt/lists/* \
    && docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
    && docker-php-ext-install -j$(nproc) gd \
    && pecl install redis swoole \
    && rm -rf /tmp/pear \
    && docker-php-ext-enable redis swoole \
    && apt-get clean && rm -rf /var/cache/apt/*

  

posted @ 2021-12-10 12:04  牧码人hhom  阅读(93)  评论(0编辑  收藏  举报