Dockerfile-如何从本地文件夹复制文件? [英] Dockerfile - How to copy files from a local folder?

查看:2071
本文介绍了Dockerfile-如何从本地文件夹复制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是 Dockerfile

FROM golang:1.14.10
MAINTAINER xyz

COPY ~/go/bin/product-api /go/bin/product-api

COPY ~/go/bin/swagger /go/bin/swagger

ENTRYPOINT ["/go/bin/product-api"]




docker build -t cloud-native-product-api:1.0.0。上,给出错误:

Step 3/5 : COPY ~/go/bin/product-api /go/bin/product-api
COPY failed: stat /var/lib/docker/tmp/docker-builder398080099/~/go/bin/product-api: no such file or directory




我认为映像构建过程将 / var / lib / docker / tmp / docker-builder398080099 作为工作区并从该路径进行引用。


I think the image build process takes /var/lib/docker/tmp/docker-builder398080099 as workspace and refer from that path.

如何将文件从本地计算机的特定文件夹复制到Docker映像中?

How to copy files from specific folder of local machine into Docker image?

推荐答案

您缺少的关键是构建的上下文,与文档的COPY部分相关:

The key thing you are missing is the build's context, relevant from the COPY part of the docs:

路径mu st位于构建上下文中;您无法复制../something / something,因为Docker构建的第一步是将上下文目录(和子目录)发送到docker守护程序。

The path must be inside the context of the build; you cannot COPY ../something /something, because the first step of a docker build is to send the context directory (and subdirectories) to the docker daemon.

> https://docs.docker.com/engine/reference/builder/#copy

上下文的描述

https:// docs。 docker.com/engine/reference/commandline/build/

但实际上,当您说 docker build directory-with-docker-file时,

But essentially, when you say "docker build directory-with-docker-file" COPY only sees files in (and below) the directory with the Dockerfile.

您可能想做的就是编译 swagger文件。

What you probably want to do is compile "swagger" during the docker build, and then put it in the path you want.

要记住的关键一件事是,Dockerfile通常是可复制的,因此,如果您在十个上运行docker build,不同的主机,将产生完全相同的图像。从主机上任意位置复制文件不会导致这种情况。

A key thing to remember is that a Dockerfile is generally meant to be reproducible such that if you run docker build on ten different hosts, the exact same image will be produced. Copying files from arbitrary locations on the host wouldn't lead to that.

这篇关于Dockerfile-如何从本地文件夹复制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆