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

DOCKER_BUILDKIT=0 is not applied by docker-compose build #8649

Closed
1 of 2 tasks
carlosdoordash opened this issue Sep 21, 2021 · 2 comments
Closed
1 of 2 tasks

DOCKER_BUILDKIT=0 is not applied by docker-compose build #8649

carlosdoordash opened this issue Sep 21, 2021 · 2 comments
Labels

Comments

@carlosdoordash
Copy link

carlosdoordash commented Sep 21, 2021

Description of the issue

Context information (for bug reports)

  • Using Compose V2 docker compose ...
  • Using Compose V1 docker-compose ...

Output of docker(-)compose version

Docker Compose version v2.0.0-rc.3

Output of docker version

Client:
 Cloud integration: 1.0.17
 Version:           20.10.8
 API version:       1.41
 Go version:        go1.16.6
 Git commit:        3967b7d
 Built:             Fri Jul 30 19:55:20 2021
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.8
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.6
  Git commit:       75249d8
  Built:            Fri Jul 30 19:52:10 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.9
  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3
 runc:
  Version:          1.0.1
  GitCommit:        v1.0.1-0-g4144b63
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Output of docker-compose config
(Make sure to add the relevant -f and other flags)

services:
  test:
    build:
      context: /Users/carlosdoordash/Projects/test
      dockerfile: /Users/carlosdoordash/Projects/test/Dockerfile
    networks:
      default: null
networks:
  default:
    name: test_default

Steps to reproduce the issue

  1. Create a Dockerfile
FROM ubuntu
RUN echo "127.0.0.1 test.localhost" >> /etc/hosts
  1. Create a docker-compose.yml
version: '3'
services:
  test:
    build:
      context: .
  1. Run docker-compose build with and without DOCKER_BUILDKIT.
$ COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1 docker-compose build
[+] Building 0.4s (5/5) FINISHED                                                                                                                                       
 => [internal] load build definition from Dockerfile                                                                                                              0.0s
 => => transferring dockerfile: 31B                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                  0.0s
 => CACHED [1/2] FROM docker.io/library/ubuntu                                                                                                                    0.0s
 => ERROR [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts                                                                                                 0.2s
------
 > [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts:
#5 0.217 /bin/sh: 1: cannot create /etc/hosts: Read-only file system
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c echo "127.0.0.1 test.localhost" >> /etc/hosts]: exit code: 2


$ COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=0 docker-compose build
[+] Building 0.4s (5/5) FINISHED                                                                                                                                       
 => [internal] load build definition from Dockerfile                                                                                                              0.0s
 => => transferring dockerfile: 31B                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                  0.0s
 => CACHED [1/2] FROM docker.io/library/ubuntu                                                                                                                    0.0s
 => ERROR [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts                                                                                                 0.3s
------
 > [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts:
#5 0.242 /bin/sh: 1: cannot create /etc/hosts: Read-only file system
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c echo "127.0.0.1 test.localhost" >> /etc/hosts]: exit code: 2


$ COMPOSE_DOCKER_CLI_BUILD=0 DOCKER_BUILDKIT=0 docker-compose build
[+] Building 0.3s (5/5) FINISHED                                                                                                                                       
 => [internal] load build definition from Dockerfile                                                                                                              0.0s
 => => transferring dockerfile: 31B                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                  0.0s
 => CACHED [1/2] FROM docker.io/library/ubuntu                                                                                                                    0.0s
 => ERROR [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts                                                                                                 0.2s
------
 > [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts:
#5 0.208 /bin/sh: 1: cannot create /etc/hosts: Read-only file system
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c echo "127.0.0.1 test.localhost" >> /etc/hosts]: exit code: 2
$
  1. Compare to running docker build with and without DOCKER_BUILDKIT.
$ DOCKER_BUILDKIT=1 docker build .                                 
[+] Building 0.4s (5/5) FINISHED                                                                                                                                       
 => [internal] load build definition from Dockerfile                                                                                                              0.0s
 => => transferring dockerfile: 36B                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                 0.0s
 => => transferring context: 2B                                                                                                                                   0.0s
 => [internal] load metadata for docker.io/library/ubuntu:latest                                                                                                  0.0s
 => CACHED [1/2] FROM docker.io/library/ubuntu                                                                                                                    0.0s
 => ERROR [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts                                                                                                 0.2s
------
 > [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts:
#5 0.233 /bin/sh: 1: cannot create /etc/hosts: Read-only file system
------
executor failed running [/bin/sh -c echo "127.0.0.1 test.localhost" >> /etc/hosts]: exit code: 2


$ DOCKER_BUILDKIT=0 docker build .
Sending build context to Docker daemon  3.072kB
Step 1/2 : FROM ubuntu
 ---> fb52e22af1b0
Step 2/2 : RUN echo "127.0.0.1 test.localhost" >> /etc/hosts
 ---> Using cache
 ---> ea73e60b789f
Successfully built ea73e60b789f

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them
$ 

Observed result

In step 3, note how running DOCKER_BUILDKIT=0 docker-compose build still results in a failed build because /etc/hosts is on a read-only filesystem.
In step 4, note how running DOCKER_BUILDKIT=0 docker build, the docker build succeeds because /etc/hosts isn't on a read-only filesystem.

Expected result

In step 3, running DOCKER_BUILDKIT=0 docker-compose build should result in a successful build.

Stacktrace / full error message

 => ERROR [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts                                                                                                 0.2s
------
 > [2/2] RUN echo "127.0.0.1 test.localhost" >> /etc/hosts:
#5 0.208 /bin/sh: 1: cannot create /etc/hosts: Read-only file system
------
failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c echo "127.0.0.1 test.localhost" >> /etc/hosts]: exit code: 2

Additional information

OS version / distribution: macOS Big Sur version 11.6
docker-compose install method: Docker Desktop version 4.0.1 (68347)

@ndeloof
Copy link
Contributor

ndeloof commented Sep 21, 2021

Compose V2 always uses BuildKit by design.
If Buildkit can't build some Dockerfile, either there's good reasons, otherwise it has to be fixed.

IIRC there's plans to make Buildkit the default builder everywhere, and maybe to drop support for classic builder at some point

@carlosdoordash
Copy link
Author

carlosdoordash commented Sep 22, 2021

I found out that when DOCKER_BUILDKIT=0, docker builds succeed by silently ignoring the change to the /etc/hosts file. I verified that the /etc/hosts file in the docker images do not have the test.localhost entries.

More detail about how the classic builder silently ignores the changes to /etc/hosts in moby/buildkit#1267 (comment)

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

No branches or pull requests

2 participants