导出makefile中的当前用户ID以进行docker-compose

rkttyhzu  于 2022-12-03  发布在  Docker
关注(0)|答案(3)|浏览(132)

I trying to pass the current user id into docker-compose.yml
How it looks in docker-compose.yml

version: '3.4'

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

Instead of CURRENT_UID=$(id -u):$(id -g) docker-compose up -d I've wrote makefile

#!/usr/bin/make

SHELL = /bin/sh

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

But CURRENT_UID still empty when I run make up
Is there a possible export uid in makefile?

qij5mzcb

qij5mzcb1#

这是我的解决方案

#!/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
rjee0c15

rjee0c152#

另一个选择是使用env
生成文件:

SHELL=/bin/bash

UID := $(shell id -u)

up:
    env UID=${UID} docker-compose up -d
holgip5t

holgip5t3#

您需要在(id -u)和(id -g)之前使用2个美元符号($$)。

#!/usr/bin/make

SHELL = /bin/sh

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

相关问题