读取Dockerfile失败;试着创造一个形象



我一直在最后一行遇到这个错误,并尝试将dockerfile放在tmp文件夹中,但仍然得到相同的错误;我甚至试过把docker的文件名大写或小写,但都没有解决问题。

我的文件路径是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"]

我在终端运行的命令:

docker build -t internhw:latest -f .Dockerfile .

终端输出:

[+] 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

终端命令输出: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

我添加了一个。dockerfile到文件夹(基本上是我通过在前面放一个句号重命名的dockerfile的副本)

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```

更新版本:

按照建议重做了docker中的运行行

#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" ] ```

当我运行在终端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

在Dockerfile里面做一个docker build是没有什么意义的…码头工人建造。

如果您需要向现有的图像添加资源,您可以在Dockerfile中使用COPY或add。

如果你需要编译一些东西,并把结果放在一个现有的映像中,你可以使用多级构建。

最新更新