Docker - [Internal] load build context: when try to build an Image
Asked Answered
C

8

7

I'm new to docker. I'm wondering what is the wrong here? this is a basic react-project that i wanted to build a docker image from it according to a tutorial that i follow.

file structure

DockerFile

FROM node:14.16-alpine3.13
COPY . /app

I got this error when i enter this command docker build -t react-app .

$ docker build -t react-app .
[+] Building 9.4s (6/7)
 => [internal] load build definition from Dockerfile                       1.7s
 => => transferring dockerfile: 31B                                        0.8s
 => [internal] load .dockerignore                                          2.0s
 => => transferring context: 2B                                            0.7s
 => [internal] load metadata for docker.io/library/node:14.16-alpine3.13   5.3s
 => [auth] library/node:pull token for registry-1.docker.io                0.0s
 => ERROR [internal] load build context                                    2.3s
 => => transferring context: 309.99kB                                      2.1s
 => [1/2] FROM docker.io/library/node:14.16-alpine3.13@sha256:7021600941a  0.0s
------
 > [internal] load build context:
------
error from sender: open node_modules\@babel\plugin-bugfix-safari-id-destructurin
g-collision-in-function-expression\lib: Access is denied.

My docker version

$ docker version
Client:
 Cloud integration: v1.0.22
 Version:           20.10.12
 API version:       1.41
 Go version:        go1.16.12
 Git commit:        e91ed57
 Built:             Mon Dec 13 11:44:07 2021
 OS/Arch:           windows/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.5.1 (74721)
 Engine:
  Version:          20.10.12
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.12
  Git commit:       459d0df
  Built:            Mon Dec 13 11:43:56 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.12
  GitCommit:        7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc:
  Version:          1.0.2
  GitCommit:        v1.0.2-0-g52b36a2
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

!Important: I changed FROM node:alpine3.13 to FROM node:14.16-alpine3.13 after posting this question.

Codify answered 27/2, 2022 at 13:11 Comment(5)
Please don't post images of text. Just include the text itself in your question, formatted as a code sample.Purapurblind
Please edit the question to include enough details to reproduce the issue. Just the diagnostic output on its own isn't enough; include at least the Dockerfile and the docker build command you used to run the image.Aldenalder
@DavidMaze my build command is docker build -t react-app . and i use only FROM and COPY in Dockerfile as shows in the uploaded image.Codify
I found few solutions for my problem. This project included .git folder that contains old files. This error was fixed once the .git folder deleted. However, It may not the least best thing to do. but in my case it worked. I should've try .dockerignore instead. Hope some docker expert give better answer.Codify
Thanks @ThusithaWickramasinghe, you've saved my day. Just deleted my repo and clone it again, and building the container is fixedFugacity
G
3

Same issue, but I made a bandaid with:

sudo chown $USER:$USER *

The problem was really me being too fast and loose with docker volumes which caused some of the files/directories in the directory with Dockerfile to be owned by root instead of "me".

The permanent fix for me is presumably to stop playing fast and loose with volume mounts.

Guesstimate answered 20/4, 2023 at 0:36 Comment(3)
Is there a fix to this without sudo? I'm in the docker group on this system, but I don't have root perms to delete the volume's folder.Amaze
if you're okay with just wiping it.. you can make docker delete it from the inside. "docker run yourvolumemount yourcontainer -- rm /my/volumn/mount" One of many reasons having 'docker' is really the same as having root.Guesstimate
oh yea I already fixed the issue but I ended up doing something similar; I spawned a new Fedora container where the root was /, and just ran the commands as usual lolAmaze
C
1

I have the same problem. After sign in (logging) at Docker Desktop, the problem was gone.

Before sign in

docker build -t my_ecom_ui .
[+] Building 2.4s (6/8)
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                               0.0s 
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                  0.0s 
 => => transferring context: 2B                                                                                                                                                                                                                                                                                    0.0s 
 => [internal] load metadata for docker.io/library/tomcat:8.5.82-jre8-openjdk                                                                                                                                                                                                                                      2.3s 
 => [auth] library/tomcat:pull token for registry-1.docker.io                                                                                                                                                                                                                                                      0.0s 
 => [1/3] FROM docker.io/library/tomcat:8.5.82-jre8-openjdk@sha256:bf1e414022830500ccace4d77dcc29017f69756225d0f4ca1477f09e8a5ce131                                                                                                                                                                                0.0s 
 => ERROR [internal] load build context                                                                                                                                                                                                                                                                            0.0s 
 => => transferring context: 87B                                                                                                                                                                                                                                                                                   0.0s 
------
 > [internal] load build context:
------

After sign in

docker build -t my_ecom_ui .
[+] Building 1.7s (8/8) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                                                                               0.0s 
 => => transferring dockerfile: 171B                                                                                                                                                                                                                                                                               0.0s 
 => [internal] load .dockerignore                                                                                                                                                                                                                                                                                  0.0s 
 => => transferring context: 2B                                                                                                                                                                                                                                                                                    0.0s 
 => [internal] load metadata for docker.io/library/tomcat:8.5.82-jre8-openjdk                                                                                                                                                                                                                                      0.7s 
 => [1/3] FROM docker.io/library/tomcat:8.5.82-jre8-openjdk@sha256:bf1e414022830500ccace4d77dcc29017f69756225d0f4ca1477f09e8a5ce131                                                                                                                                                                                0.0s 
 => [internal] load build context                                                                                                                                                                                                                                                                                  0.6s 
 => => transferring context: 79.84MB                                                                                                                                                                                                                                                                               0.6s 
 => CACHED [2/3] COPY target/ecom_ui.war /usr/local/tomcat/webapps/                                                                                                                                                                                                                                                0.0s 
 => [3/3] COPY main.config.yml /usr/local/tomcat/webapps/                                                                                                                                                                                                                                                          0.2s 
 => exporting to image                                                                                                                                                                                                                                                                                             0.0s 
 => => exporting layers                                                                                                                                                                                                                                                                                            0.0s 
 => => writing image sha256:2370e8d59bc1b3b07c4d715f5e099e0e9ba2f37e49079cbd7f7b8f0821063aef                                                                                                                                                                                                                       0.0s 
 => => naming to docker.io/library/my_ecom_ui 

enter code here
Criss answered 18/8, 2022 at 13:31 Comment(1)
Access is denied is a Windows error message, about accessing local files. That's confirmed by the solution OP posted as a comment to their original post. You seemed to have hit an authentication while pulling Docker images from Docker Hub instead.Confiscatory
G
1

Generally a matter of permissions. Quick fix: "sudo chmod -R 777 ./" from the project root directory. Although I suggest to set proper permissions instead.

Gloat answered 17/11, 2023 at 17:34 Comment(2)
chmod 777 is almost always a bad ideaTherapsid
This is bad idea, but it did work in my situation.Virescence
B
1

I found this issue on yesterday and try this post suggestion but can not fix for my case maybe I use windows and docker desktop with vs2022. In my case, I fix this issue by update docker desktop to version 4.27.2 (lastest)

Bithia answered 14/2 at 23:34 Comment(0)
E
0

Saw this post through "First answers" and wanted to clarify something. You should not include your node_modules folder in the build context and then copy it inside your Docker container, as there could be problems caused by not only different Node versions but also compiled resources in node_modules.

You should rather install the dependencies directly inside the Docker image like so :

FROM node:alpine3.13

COPY package.json package-lock.json
RUN npm ci
COPY . .

# Run project command

Finally, add a .dockerignore next to the Dockerfile with :

node_modules
Excision answered 15/2 at 17:13 Comment(1)
IMO the Docker app should automatically add node_modules to .dockerignoreCita
G
0

My issue was because I was pushing a docker image from Rider to Azure Container Registry in the background and was also attempting to do a build.

Garpike answered 12/6 at 21:13 Comment(0)
R
0

I have similar problem with docker on win10 and wsl. For me worked:

Delete all vendor files and that show me the error in permision:

rm -rf vendor

I've got this error:

rm: cannot remove 'vendor/bin/doctrine-module': Permission denied

After that, I deleted these files from the vendor directory and installed the vendor files back.

An easier solution would be to fix the permissions on this file using chmod, but for me on win, it was faster to reconstruct the vendor directory.

Rackety answered 25/7 at 15:29 Comment(0)
A
-2

Change

FROM node:14.16-alpine3.13

To

FROM node:12

that work in my case

Acme answered 6/4, 2022 at 3:49 Comment(1)
You are an amazing human being! This was the exact issue I had.Complected

© 2022 - 2024 — McMap. All rights reserved.