compose icon indicating copy to clipboard operation
compose copied to clipboard

Add environment variables for client OS/arch and client user UID/GID

Open arnested opened this issue 1 year ago • 1 comments

When using Docker Compose for development setup, you often need to tweak the configuration to vary on Linux, macOS, and Windows. And some services you would like to run with the same UID/GID as your current client user.

To help with that, we introduce four new environment variables while parsing the configuration files:

  • COMPOSE_CLIENT_OS: set to Go's runtime.GOOS
  • COMPOSE_CLIENT_ARCH: set to Go's runtime.GOARCH
  • COMPOSE_CLIENT_UID: set to the current users UID
  • COMPOSE_CLIENT_GUID: set to the current users GID

This way, we can now have a Docker Compose setup like this:

compose.yaml:

services:
  php:
    image: php
    volumes:
      - .:/code
    user: ${COMPOSE_CLIENT_UID}:${COMPOSE_CLIENT_GID}
  web:
    image: apache
    extends:
      file: compose.${COMPOSE_CLIENT_OS}.yaml
      service: web

compose.linux.yaml:

services:
  web:
    environment:
      VIRTUAL_HOST: mysite.local

compose.darwin.yaml:

services:
  web:
    environment:
      VIRTUAL_HOST: mysite.docker

Closes #11820.

arnested avatar May 15 '24 13:05 arnested

This is basically the same I proposed as https://github.com/compose-spec/compose-go/pull/572 which was rejected as this introduce portability issues.

Also, runtime.GOARCH is very specific to golang, I'd prefer we rely on uname values. But I don't understand the use-case for this one. Would you like a Linux container to run with reference to some OSX or Windows -specific file vs the native one?

ndeloof avatar May 17 '24 13:05 ndeloof