首页 > 解决方案 > 为 docker-compose 导出 makefile 中的当前用户 ID

问题描述

我试图将当前用户 ID 传递给docker-compose.yml

它看起来如何docker-compose.yml

version: '3.4'

services:
    app:
        build:
            context: ./
            target: "php-${APP_ENV}"
        user: "${CURRENT_UID}"

而不是CURRENT_UID=$(id -u):$(id -g) docker-compose up -d我写了makefile

#!/usr/bin/make

SHELL = /bin/sh

up: 
    export CURRENT_UID=$(id -u):$(id -g)
    docker-compose up -d

CURRENT_UID我跑的时候还是空的make up

makefile中是否有可能的导出uid?

标签: dockermakefiledocker-compose

解决方案


这是我的解决方案

#!/usr/bin/make

SHELL = /bin/sh

CURRENT_UID := $(shell id -u)
CURRENT_GID := $(shell id -g)

export CURRENT_UID
export CURRENT_GID

up: 

    docker-compose up -d

推荐阅读