I would like to build a new image with docker build using docker desktop. It seems that the build context might not be available for the build process.
FROM apache/airflow:2.8.0-python3.8
ADD /tmp/requirements.txt .
RUN pip install apache-airflow==2.2.0 -r requirements.txt
It produces the following error:
❯ docker build - < Dockerfile_local
[+] Building 3.3s (6/7) docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 195B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load metadata for docker.io/apache/airflow:2.8.0-python3.8 3.3s
=> [internal] load build context 0.0s
=> => transferring context: 2B 0.0s
=> CANCELED [1/3] FROM docker.io/apache/airflow:2.8.0-python3.8@sha256:6d9a8f90ad5d6005f81b9a059134237f4f970b91d282799 0.0s
=> => resolve docker.io/apache/airflow:2.8.0-python3.8@sha256:6d9a8f90ad5d6005f81b9a059134237f4f970b91d282799a350f7dda 0.0s
=> => sha256:6d9a8f90ad5d6005f81b9a059134237f4f970b91d282799a350f7ddace6ab1a5 1.61kB / 1.61kB 0.0s
=> => sha256:d7d27a316f5cd64a0b6eb87047ac04203c8b667a2c363e623bc326e8ea6665d7 25.67kB / 25.67kB 0.0s
=> => sha256:180b4f3737b0430931e906094d02b0728912110b90c83ae7ffc467a0b01ba4fa 4.47kB / 4.47kB 0.0s
=> ERROR [2/3] ADD /tmp/requirements.txt . 0.0s
------
> [2/3] ADD /tmp/requirements.txt .:
------
Dockerfile:2
--------------------
1 | FROM apache/airflow:2.8.0-python3.8
2 | >>> ADD /tmp/requirements.txt .
3 | RUN pip install apache-airflow==2.2.0 -r requirements.txt
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref f9dd9b67-5ecf-41ed-beed-87bfda7e1dfd::8el50kgcmxh0ay9r8ue7zhgp1: failed to walk /var/lib/docker/tmp/buildkit-mount348437173/tmp: lstat /var/lib/docker/tmp/buildkit-mount348437173/tmp: no such file or directory
View build details: docker-desktop://dashboard/build/desktop-linux/desktop-linux/10tveo6gaue4pbz92r0mnwvgc
Is there a way to share a file with the build context like this?
2
Answers
Move the requirements.txt to the same path as Dockerfile and then change the ADD command to:
ADD requirements.txt .
If this works, thsi will serve as a sanity check that will allow you to narrow the problem to the tmp path.
I believe the error is due to using
docker build
with- < Dockerfile_local
, which pipes the Dockerfile into Docker build from standard input (stdin). This wouldn’t include any local files (like yourrequirements.txt
) in the build context, and that’s why Docker cannot findrequirements.txt
when it tries toADD
it to ADD it to the image.Make sure
requirements.txt
is located in the directory where you’re running thedocker build
command. The build context should be a directory, not stdin, so that Docker can access local files.Modify the
ADD
command in your Dockerfile to correctly referencerequirements.txt
from within the build context. Ifrequirements.txt
is in the same directory as the Dockerfile, the reference is correct as it currently is. Also, ensure the path is relative to the build context’s root:Instead of piping the Dockerfile into
docker build
, run the command in the directory containing both the Dockerfile andrequirements.txt
, specifying the directory as the build context: