Reputation: 21
I keep running into that error on the last line and have tried putting the dockerfile in the tmp folder but still get the same error; I even tried upper casing and lowercasing the docker file name, it didn't resolve the issue.
my file path is Users/maheenk/Desktop/infra
my docker file :
#syntax=docker/dockerfile:1
#using latest version
FROM golang:latest
WORKDIR /app
#Download necessary Go modules
COPY go.mod ./
COPY go.sum ./
RUN go mod download
#copies source code onto image
COPY *.go ./
#static application in rootfilesystem
RUN docker build -t internhw:latest -f .Dockerfile .
EXPOSE 8080
#command to execute when image is used to start a container
CMD [ "internhw"]
the command I run in terminal:
docker build -t internhw:latest -f .Dockerfile .
what the output is in terminal:
[+] Building 0.1s (2/2) FINISHED
=> [internal] load build definition from .Dockerfile 0.1s
=> => transferring dockerfile: 2B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount200403056/.Dockerfile: no such file or directory
Output of command in terminal: ls -al
total 160
drwxrwxr-x@ 9 maheenk staff 288 Apr 24 11:42 .
drwxrwxrwx@ 110 maheenk staff 3520 Apr 23 17:24 ..
-rw-r--r--@ 1 maheenk staff 6148 Apr 24 11:42 .DS_Store
drwxr-xr-x 14 maheenk staff 448 Apr 24 11:00 .git
-rw-r--r--@ 1 maheenk staff 523 Apr 24 10:54 Dockerfile
-rw-r--r-- 1 maheenk staff 669 Apr 23 16:26 go.mod
-rw-r--r-- 1 maheenk staff 56262 Apr 23 16:26 go.sum
-rw-r--r-- 1 maheenk staff 2126 Apr 23 16:09 main.go
I added a .Dockerfile to the folder(basically a copy of the dockerfile that i renamed by putting a period in front of)
drwxrwxr-x@ 9 maheenk staff 288 Apr 24 13:03 .
drwxrwxrwx@ 111 maheenk staff 3552 Apr 24 12:43 ..
-rw-r--r--@ 1 maheenk staff 6148 Apr 24 13:03 .DS_Store
-rw-r--r--@ 1 maheenk staff 513 Apr 24 13:06 .Dockerfile
drwxr-xr-x 14 maheenk staff 448 Apr 24 13:00 .git
-rw-r--r--@ 1 maheenk staff 523 Apr 24 10:54 Dockerfile
-rw-r--r-- 1 maheenk staff 669 Apr 23 16:26 go.mod
-rw-r--r-- 1 maheenk staff 56262 Apr 23 16:26 go.sum
-rw-r--r-- 1 maheenk staff 2126 Apr 23 16:09 main.go```
UPDATED VERSION:
redid the run line in docker as suggested
#syntax=docker/dockerfile:1
FROM golang:latest
WORKDIR /app
# Download necessary Go modules
COPY go.mod ./
COPY go.sum ./
RUN go mod download
#copies source code onto image
COPY *.go ./
#static application in rootfilesystem
RUN build -t internhw:latest .Dockerfile .
EXPOSE 8080
#command to execute when image is used to start a container
CMD [ "internhw" ] ```
when i run in terminal docker build -t internhw:latest .Dockerfile .
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build an image from a Dockerfile
Upvotes: 2
Views: 474
Reputation: 1325017
It does make little sense to do a docker build
inside a Dockerfile which is itself... 'docker built'.
If you need to add resources to an existing image, you can use COPY or ADD inside your Dockerfile
.
If you need to compile something and put the result in an existing image, you can use a multi-stage build.
Upvotes: 1