Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bad file descriptor ERROR during apk update in Docker container... Why?

After running:

docker network rm $NETNAME
docker network create --driver bridge $NETNAME --subnet "${SUBNET}0/24"
docker run --name $NODENAME -it --net $NETNAME --ip 192.168.0.2 --volume --detach $IMGNAME

inside the container, as root, I run apk udpdate:

# apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.7/main: Bad file descriptor
WARNING: Ignoring APKINDEX.70c88391.tar.gz: Bad file descriptor
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.7/community: Bad file descriptor
WARNING: Ignoring APKINDEX.5022a8a2.tar.gz: Bad file descriptor
2 errors; 33 distinct packages available

... and hit the Bad file descriptor error.

There a number of other folks that have encountered the same error:

CDN seems to be down and cannot get mirrors working #280

Repository problem? #279

Suggestions on how to resolve this range from:

"It's a DNS lookup error. Just add google DNS servers (8.8.8.8, 8.8.4.4) to your Docker host's deamon config file."

... to ...

"Add the following to your Dockerfile:"

RUN echo http://mirror.yandex.ru/mirrors/alpine/v3.5/main > /etc/apk/repositories; \ echo http://mirror.yandex.ru/mirrors/alpine/v3.5/community >> /etc/apk/repositories

(Which you should NOT do. Never add packages from non-official sources.)

Solution

The solution was easy enough. Add these 2 lines to your RUN command:

rm -rf /var/cache/apk && \
mkdir /var/cache/apk && \

In Dockerfile ...

RUN apk add --update --no-cache bash \
    git \
    make \
    clang \
    g++ \
    go && \
    mkdir -p $REPO && \
    mkdir -p $GODIR/src && \
    rm -rf /usr/share/man && \
    rm -rf /var/cache/apk && \
    mkdir /var/cache/apk && \
    apk del git clang

Adding commands to delete and recreate the /var/cache/apk directory feels like a hack.

My hack works, but what is the root cause of this error and who should fix it?

like image 412
l3x Avatar asked Feb 11 '18 20:02

l3x


1 Answers

--no-cache option allows to not cache the index locally. That is helpful in keeping the container small.

Also, it is equivalent to apk update at the top and rm -rf /var/cache/apk/ in the end.

So you can try to use it this way:

RUN apk add --update --no-cache bash \
    git \
    make \
    clang \
    g++ \
    go && \
    mkdir -p $REPO && \
    mkdir -p $GODIR/src && \
    rm -rf /usr/share/man && \
    apk del git clang
like image 183
mayankSinha Avatar answered Oct 19 '22 09:10

mayankSinha