skip to Main Content

I have a CentOS 7.0 host machine Docker version 19.03.4, build 9013bf583a installed. I am trying to create a simple docker image

I have a the following Docker file.

FROM alpine:edge
MAINTAINER javaonfly
RUN apk update && apk add --no-cache openjdk8

(Please note that I have updated the RUN command to have “update” based on the answer given by LinPy below)
In the above docker file, I am simply using alpine:edge as base docker container and then update it with openjdk8. I then execute the following command

sudo docker build --network=host --file=docker.txt --tag=myrep/image1 --rm=true .

I see the following output

Sending build context to Docker daemon  87.04MB
Step 1/3 : FROM alpine:edge
 ---> 7eacb6761fa1
Step 2/3 : MAINTAINER javaonfly
 ---> Using cache
 ---> 77818d634212
Step 3/3 : RUN apk update && add --no-cache openjdk8
 ---> Running in d438f2522d6a
fetch http://dl-cdn.alpinelinux.org/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/edge/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/main: network error (check Internet connection and firewall)
WARNING: Ignoring APKINDEX.066df28d.tar.gz: No such file or directory
ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/community: network error (check Internet connection and firewall)
WARNING: Ignoring APKINDEX.b53994b4.tar.gz: No such file or directory
2 errors; 14 distinct packages available
The command '/bin/sh -c apk update && add --no-cache openjdk8' returned a non-zero code: 2

On the host machine, I can successfully run the command docker run hello-world. I can also ping to www.google.com from host machine. But, it seems the alpine:edge container is not able to connect to internet.

I have also shelled into alpine:edge container with this command and executed the command ping www.google.com inside the shell, but the ping is stuck with no result.

sudo docker run -it --rm alpine:edge

Following is the result of the ifconfig command in the alpine:edge shell

eth0      Link encap:Ethernet  HWaddr 02:42:C0:A8:DC:01
          inet addr:192.168.220.1  Bcast:192.168.220.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:9 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:698 (698.0 B)  TX bytes:630 (630.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

following is the result of the ip addr show command on the host machine.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:50:56:bf:b9:c6 brd ff:ff:ff:ff:ff:ff
    inet 10.211.164.24/32 brd 10.211.164.24 scope global noprefixroute ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:febf:b9c6/64 scope link noprefixroute
       valid_lft forever preferred_lft forever
16: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default
    link/ether 02:42:6f:8a:2e:79 brd ff:ff:ff:ff:ff:ff
    inet 192.168.220.2/24 brd 192.168.220.255 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:6fff:fe8a:2e79/64 scope link
       valid_lft forever preferred_lft forever

I have gone through many questions in SO related to this issue, but none of them solved my issue.

3

Answers


  1. Chosen as BEST ANSWER

    I have resolved this issue. My host was behind a proxy server. It seems the docker build command also needs to mention the proxy server. I executed the following command which resolved my issue.

    sudo docker build --build-arg http_proxy=http://proxyserver:8080 --build-arg https_proxy=https://proxyserver:8080 --file=dockerfile.txt --tag=myrep/image1 --rm=true .
    

  2. try to update first:

    FROM alpine:edge
    MAINTAINER javaonfly
    RUN rm -rf /var/cache/apk/* && rm -rf /tmp/*
    RUN apk update && apk add --no-cache openjdk8
    
    Login or Signup to reply.
  3. Same problem.
    Docker version 19.03.8 on CentOS host.
    From inside the container:

    • ping external ip OK
    • dns resolution OK
    • apk add -> ERROR: http://dl-cdn.alpinelinux.org/alpine/edge/main: network error
      during the build of alpine-jdk without specifying the –network option (so using the default bridge mode).
      We solved by setting the parameter –network=host in the alpine-jdk build:
    docker build --network=host --file=Dockerfile-jdk8 --tag=alpine-jdk:base --rm=true .
    

    Dockerfile-jdk8:

    FROM alpine:edge
    RUN apk add --no-cache openjdk8
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search