【问题标题】:Dockerfile build error when use apt-get install gcc使用 apt-get install gcc 时 Dockerfile 构建错误
【发布时间】:2017-01-13 12:23:09
【问题描述】:

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

FROM ubuntu:16.04
COPY hd* ./

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

ENTRYPOINT ./hellodocker

工人目录如下:

$ 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

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

【问题讨论】:

    标签: docker dockerfile docker-build


    【解决方案1】:

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

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

    你想要&amp;&amp;

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

    【讨论】:

      【解决方案2】:

      你应该使用 apt-get update &amp;&amp; apt-get -y install gcc 和双 '&'

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2023-02-05
        • 2023-03-11
        • 1970-01-01
        • 1970-01-01
        • 2014-02-16
        • 2014-07-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多