dev:参数从docker-compose传递到dockerfile

This commit is contained in:
liubocheng 2025-04-04 22:07:29 +08:00
parent 76e96d4af1
commit ecc2f51722
2 changed files with 9 additions and 5 deletions

View File

@ -1,7 +1,11 @@
version: '3.8' version: '3.8'
services: services:
php: php:
build: . # 指向 Dockerfile 目录 build:
context: .
args:
USER_ID: "1003"
GROUP_ID: "1003"
volumes: volumes:
- /data/laravel_test:/var/www/html - /data/laravel_test:/var/www/html
working_dir: /var/www/html working_dir: /var/www/html

View File

@ -1,4 +1,6 @@
FROM php:7.3-fpm FROM php:7.3-fpm
ARG USER_ID
ARG GROUP_ID
# 替换为清华大学镜像源Debian 10 Buster # 替换为清华大学镜像源Debian 10 Buster
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \ RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list \
@ -16,8 +18,6 @@ RUN curl -sS https://getcomposer.org/installer | php -- \
--filename=composer --filename=composer
# 创建非 root 用户(推荐与宿主机用户 UID/GID 一致) # 创建非 root 用户(推荐与宿主机用户 UID/GID 一致)
ARG USER_ID=1003 # 宿主机 deploy-user 的 UID
ARG GROUP_ID=1003 # 宿主机 deploy-user 的 GID
RUN groupadd -g ${GROUP_ID} appuser \ RUN groupadd -g ${GROUP_ID} appuser \
&& useradd -u ${USER_ID} -g appuser -m -d /home/appuser -s /bin/bash appuser && useradd -u ${USER_ID} -g appuser -m -d /home/appuser -s /bin/bash appuser