当前位置: 首页 > 工具软件 > hyperf-admin > 使用案例 >

hyperf docker-compoose 安装 附带mongo安装 mongo php扩展

郎星汉
2023-12-01

我想玩下mongo但是hyperf官网给的自带镜像没有这个扩展所以用下载下来的dockerfile自己修改下进行build

dockerfile配置如下

# Default Dockerfile
#
# @link     https://www.hyperf.io
# @document https://hyperf.wiki
# @contact  group@hyperf.io
# @license  https://github.com/hyperf/hyperf/blob/master/LICENSE

FROM hyperf/hyperf:7.4-alpine-v3.11-swoole
LABEL maintainer="Hyperf Developers <group@hyperf.io>" version="1.0" license="MIT" app.name="Hyperf"

##
# ---------- env settings ----------
##
# --build-arg timezone=Asia/Shanghai
ARG timezone

ENV TIMEZONE=${timezone:-"Asia/Shanghai"} \
    APP_ENV=prod \
    SCAN_CACHEABLE=(true)

# update
RUN set -ex \
    # show php version and extensions
    && php -v \
    && php -m \
    && php --ri swoole \
    #  ---------- some config ----------
    && cd /etc/php7 \
    # - config PHP
    && { \
        echo "upload_max_filesize=128M"; \
        echo "post_max_size=128M"; \
        echo "memory_limit=1G"; \
        echo "date.timezone=${TIMEZONE}"; \
    } | tee conf.d/99_overrides.ini \
    # - config timezone
    && ln -sf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \
    && echo "${TIMEZONE}" > /etc/timezone \
    # ---------- clear works ----------
    && rm -rf /var/cache/apk/* /tmp/* /usr/share/man \
    && echo -e "\033[42;37m Build Completed :).\033[0m\n"

RUN set -ex \
    && apk add php7-mongodb

docker-compose.yml 如下
version: '3'
services:
  mysql:
    image: mysql:8.0
    container_name: stock-mysql
    restart: always
    ports:
      - "33066:3306"
    volumes:
      - ./docker-config/mysql/lib/mysql:/var/lib/mysql
      - ./docker-config/mysql/my.cnf:/etc/mysql/conf.d/my.cnf
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=root
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    networks:
      - hdzs_net
  redis:
    image: redis
    container_name: stock-redis
    restart: always
    ports:
      - "63798:6379"
    volumes:
      - ./docker-config/redis/data/:/data/
      - ./docker-config/redis/redis.conf:/redis.conf
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    networks:
      - hdzs_net
    command: redis-server --requirepass root --appendonly yes
    logging:
      driver: "json-file"
      options:
        max-size: "1m"
  hyperf:
    build: ./docker
    container_name: hyperf-stock
    restart: always
    working_dir: /data
    ports:
      - "9505:9505"
      - "9506:9506"
    volumes:
      - "./:/data"
    stdin_open: true
    tty: true
    networks:
      - hdzs_net
  mongo:
    container_name: mongo
    image: mongo # 可以修改为自己需要的版本
    restart: always         # 是否重启
    networks:
      - hdzs_net
    ports:
      - 27017:27017
    environment:
      MONGO_INITDB_ROOT_USERNAME: root  # 如果密码不生效,删除映射文件
      MONGO_INITDB_ROOT_PASSWORD: example
    volumes:
      - /etc/localtime:/etc/localtime # 时区
      - ./docker-config/mongodb/data/db:/data/db # 挂载数据目录
      - ./docker-config/mongodb/data/log:/var/log/mongodb  # 挂载日志目录
      - ./docker-config/mongodb/data/config:/etc/mongo  # 挂载配置目录
  mongo-express:
    image: mongo-express
    container_name: mongo-ui
    restart: always
    ports:
        - 8086:8081
    networks:
        - hdzs_net
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
      ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/
networks:
  hdzs_net:
感谢 【docker】 docker安装MongoDB数据库_可爱+小可爱的博客-CSDN博客_docker下安装mongodb 给的mongo安装给的参考方案

hyperf  dockefile 地址 Docker Hub

 类似资料: