Skip to content

[BUG] DOCKER_DEFAULT_PLATFORM environment variable not working #10041

@jensschulze

Description

@jensschulze

Description

I am having platform issues on a M1 MacBook pro: Docker Compose v2.13.0 (which comes bundled with Docker Desktop 4.15.0) seems to ignore the environment variable DOCKER_DEFAULT_PLATFORM.

Environment

  • Apple MacBook pro (14", 2021), M1, 32 GByte, macOS Monterey 12.6.1
  • Docker Desktop 4.15.0

docker pull

no platform specified

$ docker pull mysql:5.7
5.7: Pulling from library/mysql
no matching manifest for linux/arm64/v8 in the manifest list entries

Works as expected.

environment variable is set

$ DOCKER_DEFAULT_PLATFORM=linux/x86_64 docker pull mysql:5.7
5.7: Pulling from library/mysql
Digest: sha256:4149a92977a54d27cbd6f81cca3817e6278a844d566b45f9ff1908bb2714b1ca
Status: Image is up to date for mysql:5.7
docker.io/library/mysql:5.7

Works as expected.

Steps To Reproduce

docker compose

Let’s use this super simple demo file:

version: "3"

services:
  db:
    image: mysql:5.7
    environment:
      - MYSQL_ROOT_PASSWORD=secure1234
    ports:
      - "3306:3306"

No platform specified

$ docker compose up
[+] Running 1/0
 ⠿ Container test-db-1  Created                                                                                                                                                                                                          0.0s
Attaching to test-db-1
test-db-1  | 2022-12-03 09:07:12+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
test-db-1  | 2022-12-03 09:07:13+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
…

Does not work as expected (does not complain).

Environment variable is set

$ DOCKER_DEFAULT_PLATFORM=linux/x86_64 docker compose up
[+] Running 2/0
 ⠿ Network test_default                                                                                                                              Created                                                                             0.0s
 ⠿ Container test-db-1                                                                                                                               Created                                                                             0.0s
 ⠋ db The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested                                                                                     0.0s
Attaching to test-db-1
test-db-1  | 2022-12-03 09:09:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
test-db-1  | 2022-12-03 09:09:10+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
…

Does not work as expected (complains although a default is set)

This has worked before, we are using docker compose every day. This behavior was introduced with the newest version of Docker Desktop. If you export the variable instead of setting it, the behavior is the same.

In the Release notes for v2.13.0 there is even a bullet point stating:

Compose now uses the platform value defined by DOCKER_DEFAULT_PLATFORM when no service.platform defined. Fixed compose#9889

Platform in compose file

Add the platform key to the compose file:

version: "3"

services:
  db:
    image: mysql:5.7
    platform: linux/x86_64
    environment:
      - MYSQL_ROOT_PASSWORD=secure1234
    ports:
      - "3306:3306"

… and it works:

$ docker compose up
[+] Running 2/0
 ⠿ Network test_default  Created                                                                                                                                                                                                         0.0s
 ⠿ Container test-db-1   Created                                                                                                                                                                                                         0.0s
Attaching to test-db-1
test-db-1  | 2022-12-03 09:16:43+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.40-1.el7 started.
test-db-1  | 2022-12-03 09:16:44+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
…

It still works if you specifically set or export the environment variable.

This is the expected behavior, but we do not want to specify the platform in every service in the docker-compose.yml.

Compose Version

v2.13.0

Docker Environment

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.9.1)
  compose: Docker Compose (Docker Inc., v2.13.0)
  dev: Docker Dev Environments (Docker Inc., v0.0.5)
  extension: Manages Docker extensions (Docker Inc., v0.2.16)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.22.0)

Server:
 Containers: 2
  Running: 0
  Paused: 0
  Stopped: 2
 Images: 121
 Server Version: 20.10.21
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: runc io.containerd.runc.v2 io.containerd.runtime.v1.linux
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc version: v1.1.4-0-g5fd4c4d
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.49-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 4
 Total Memory: 15.61GiB
 Name: docker-desktop
 ID: VLWY:LLVX:OOSQ:EUFT:3YWZ:AYYJ:AV3Y:RJZM:JJBU:YUGN:I2X7:JM66
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions