LoranceChen
LoranceChen

Reputation: 2574

Dockerfile build error when use apt-get install gcc

I attempt build a "helloworld" c program to image but a build error occurred when parse RUN apt-get update & apt-get -y install gcc with cmd sudo docker build .
Dockerfile is very simple as this:

FROM ubuntu:16.04
COPY hd* ./

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

ENTRYPOINT ./hellodocker

worker dir as this:

$ 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 is:

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

Error encounter when use 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

The tips is very rough, does someone know what's the matter it is? Thanks

Upvotes: 1

Views: 6774

Answers (2)

Matt
Matt

Reputation: 74680

A single ampersand will background a task, which means the install starts running before the update is finished.

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

You want &&

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

Upvotes: 5

n2o
n2o

Reputation: 6477

You should use apt-get update && apt-get -y install gcc with double '&'

Upvotes: 2

Related Questions