Dolphin
Dolphin

Reputation: 38677

why docker build send build context to docker daemon so slow

This is my dockerfile:

FROM nginx:1.21.1

ENV LANG=en_US.UTF-8 \
    LC_ALL=en_US.UTF-8 \
    TZ=Asia/Shanghai

MAINTAINER huanghaihua
ADD build/  /usr/share/nginx/html/
COPY default.conf  /etc/nginx/conf.d/default.conf

EXPOSE 80

when I am using this command to build on server side:

➜  pc-super-open git:(5b89d40) docker build -f ./Dockerfile -t=hades-pro/pc-super-frontend:1.0.0 .
Sending build context to Docker daemon  357.1MB

The send build context step takes more than 10 minites. On my local machine, it complete less than 2 seconds. I am build on iMac (16GB RAM + 512GB), why takes so long? what should I do to fix this problem? I have tried to store the nginx image in aliyun(avoid download big image from docker from different country):

docker tag nginx:1.21.1 registry.cn-hangzhou.aliyuncs.com/dabai_app_k8s/nginx:1.21.1 
docker push registry.cn-hangzhou.aliyuncs.com/dabai_app_k8s/nginx:1.21.1

and change the Dockerfile like this:

FROM registry.cn-hangzhou.aliyuncs.com/dabai_app_k8s/nginx:1.21.1

still not fix the problem, still very slow.

Upvotes: 5

Views: 4610

Answers (1)

Charles Desbiens
Charles Desbiens

Reputation: 1079

The "Sending build context" step is unrelated to the base image download. This step takes a long time because you are running on a remote builder, and your build command is using "." as its build context. This means that the entire contents of your local directory have to be sent over the network to the machine you are building your image on. This is also why it's much faster on your local machine; it doesn't need to transfer your local directory over.

if you add a .dockerignore file to your local directory, you can limit what gets transferred by listing any unnecessary files/directories in there. This will speed up this step.

Upvotes: 9

Related Questions