gpt4 book ai didi

docker - 使用apt-get install gcc时Dockerfile构建错误

转载 作者:行者123 更新时间:2023-12-02 20:39:19 25 4
gpt4 key购买 nike

我尝试构建一个“helloworld” C程序进行镜像,但是使用cmd RUN apt-get update & apt-get -y install gcc解析sudo docker build .时发生了构建错误Dockerfile非常简单,如下所示:

FROM ubuntu:16.04
COPY hd* ./

RUN apt-get update & apt-get -y install gcc
RUN gcc ./hd.c -o hellodocker

ENTRYPOINT ./hellodocker

worker 目录是这样的:
$ ls -al
total 32
drwxr-xr-x 2 root root 4096 Sep 6 02:42 .
drwxr-xr-x 7 root root 4096 Sep 5 23:12 ..
-rw-r--r-- 1 root root 386 Sep 6 02:38 Dockerfile
-rw-r--r-- 1 root root 81 Sep 6 01:35 hd.c

hd.c是:
$ cat hd.c 
#include <stdio.h>
int main(int argc, char **argv) { printf("hello docker\n"); }

使用sudo docker build . 时遇到错误:
$ sudo docker build .
Sending build context to Docker daemon 13.31 kB
Step 1 : FROM ubuntu:16.04
---> bd3d4369aebc
Step 2 : COPY hd* ./
---> Using cache
---> 348a98d816f0
Step 3 : RUN apt-get update & apt-get -y install gcc
---> Running in 205cd4de149c
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package gcc
The command '/bin/sh -c apt-get update & apt-get -y install gcc' returned a non-zero code: 100

提示很粗糙,有人知道这是怎么回事吗?谢谢

最佳答案

单个&字符将使任务后台运行,这意味着installupdate完成之前正在运行。

apt-get update & apt-get -y install gcc

您想要 &&
apt-get update && apt-get -y install gcc

关于docker - 使用apt-get install gcc时Dockerfile构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39342310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com