Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export current user id in makefile for docker-compose

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?

like image 713
matchish Avatar asked Apr 30 '19 08:04

matchish


2 Answers

Here is my solution

#!/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
like image 154
matchish Avatar answered Nov 02 '22 09:11

matchish


Another option is to use env:

Makefile:

SHELL=/bin/bash

UID := $(shell id -u)

up:
    env UID=${UID} docker-compose up -d
like image 4
Eddie Avatar answered Nov 02 '22 09:11

Eddie