Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arnested
Copy link

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.

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:
```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:
```yaml
services:
  web:
    environment:
      VIRTUAL_HOST: mysite.local
```

compose.darwin.yaml:
```yaml
services:
  web:
    environment:
      VIRTUAL_HOST: mysite.docker
```

Closes docker#11820.

Signed-off-by: Arne Jørgensen <arne@arnested.dk>
@ndeloof
Copy link
Contributor

ndeloof commented May 17, 2024

This is basically the same I proposed as compose-spec/compose-go#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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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