【问题标题】:How to create custom image in docker using VSCode?如何使用 VSCode 在 docker 中创建自定义图像?
【发布时间】:2020-12-11 07:41:47
【问题描述】:

我是 docker 新手,我正在使用 VSCode 创建新的自定义 alpine docker 映像。以下是我在文件(Dockerfile)中提到的一组命令:

# Step1 specify the base image
FROM alpine

# Download and install dependencies
RUN apk add --update redis

# Setup the startup command
CMD ["redis-server"]

现在,当我在 vs 终端中运行 docker build 命令时,出现错误,

PS C:\Users\ankurpandey\Desktop\StudyMaterial\dockerfile-custom> docker build .

[+] Building 0.1s (2/2) FINISHED

 => [internal] load .dockerignore 0.1s
 => transferring context: 2B 0.0s  
 => [internal] load build definition from Dockerfile 0.0s  
 => transferring dockerfile: 2B 0.0s 

failed to solve with frontend dockerfile.v0: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount460459348/Dockerfile: no such file or directory    

我在我的根文件夹 dockerfile-custom 中只创建了一个普通文件,即 Dockerfile如图所示

请告诉我这些步骤出了什么问题?谢谢!!

【问题讨论】:

  • 你能展示一下你的 .dockerignore 里有什么吗?
  • 能否请您显示当前工作目录(dockerfile-custom)的所有内容?
  • 我已经用工作目录的文件夹结构更新了帖子。 @MetallimaX,我在 vscode 更改中没有任何带有 .dockerignore 的文件。

标签: visual-studio docker visual-studio-code dockerfile docker-machine


【解决方案1】:

我看到你正在尝试构建一个 redis-server,redis 的图像已经在 docker hub 上可用 - 你试过了吗?

https://hub.docker.com/_/redis

Check this link - the same issue is discussed and resolved.

它似乎在 Windows 上 - 如果你尝试

docker build -f <name of your dockerfile> .

它应该可以正常工作。

【讨论】:

  • 我已经尝试了上面的命令,但是它抛出了一个错误,因为“docker build”需要 1 个参数。”
  • @AnkurPandey 添加一个“。”最后表示dockerfile所在的当前目录。
  • @vpn -- 从 'dockerfile' 更改名称 'Dockerfile' 对我有用。谢谢!!
猜你喜欢
  • 2020-06-06
  • 2019-09-22
  • 2017-01-21
  • 2012-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多