0

I created a strapi V4 project according to the Quick Start Guide.

Next I built it as described in the docs Running Strapi in a Docker container using this Dockerfile:

FROM node:16-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
ENV NODE_ENV=${NODE_ENV}
WORKDIR /opt/
COPY ./package.json ./yarn.lock ./

##  copy yarn-related configfiles
COPY ./.npmrc ./.yarnrc ./.yarnrc.yml ./

ENV PATH /opt/node_modules/.bin:$PATH

ENV HTTP_PROXY=${HTTP_PROXY}
ENV HTTPS_PROXY=${HTTPS_PROXY}
ENV NO_PROXY=${NO_PROXY}
ENV http_proxy=${http_proxy}
ENV https_proxy=${https_proxy}
ENV no_proxy=${no_proxy}

RUN yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
EXPOSE 1337
CMD ["yarn", "develop"]

The proxy environment variables seemed necessary as I am behind a HTTP proxy server, but they do not improve anything with respect to the build duration. Also the npm and yarn configs (also containing my proxy settings) are not helpful. In the end I had an image after . This is the build output:

$ docker build --build-arg NODE_ENV=development -t mystrapi-demo-development:latest -f Dockerfile my-project
[+] Building 2963.9s (14/14) FINISHED
 => [internal] load build definition from Dockerfile                                                                                          0.0s
 => => transferring dockerfile: 760B                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                             0.0s
 => => transferring context: 2B                                                                                                               0.0s
 => [internal] load metadata for docker.io/library/node:16-alpine                                                                             0.9s
 => [internal] load build context                                                                                                             2.0s
 => => transferring context: 4.03MB                                                                                                           2.0s
 => [1/9] FROM docker.io/library/node:16-alpine@sha256:f1657204d3463bce763cefa5b25e48c28af6fe0cdb0f68b354f0f8225ef61be7                       0.0s
 => CACHED [2/9] RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev                 0.0s
 => CACHED [3/9] WORKDIR /opt/                                                                                                                0.0s
 => CACHED [4/9] COPY ./package.json ./yarn.lock ./                                                                                           0.0s
 => CACHED [5/9] COPY ./.npmrc ./.yarnrc ./.yarnrc.yml ./                                                                                     0.0s
 => [6/9] RUN yarn config set network-timeout 600000 -g && yarn install                                                                      46.0s
 => [7/9] WORKDIR /opt/app                                                                                                                    0.2s
 => [8/9] COPY ./ .                                                                                                                           4.9s
 => [9/9] RUN yarn build                                                                                                                   2884.3s
 => exporting to image                                                                                                                       25.6s
 => => exporting layers                                                                                                                      25.6s
 => => writing image sha256:d88433bf7cba79b39674996dbc328135f6683c8d78d6ddc4914de477ab12b20a                                                  0.0s
 => => naming to docker.io/library/mystrapi-demo-development:latest                                                                           0.0s

It took more than 2800s to yarn build. I traced the network traffic and encountered lines like this:

18:44:45.011608 veth6ea24c9 P   IP 192.168.1.1.44756 > 104.16.27.35.443: Flags [P.], seq 1:375, ack 1, win 502, options [nop,nop,TS val 2249181641 ecr 4109794444], length 374
18:44:45.011608 docker0 In  IP 192.168.1.1.44756 > 104.16.27.35.443: Flags [P.], seq 1:375, ack 1, win 502, options [nop,nop,TS val 2249181641 ecr 4109794444], length 374
18:44:45.012068 docker0 Out IP 10.100.200.5 > 192.168.1.1: ICMP 104.16.27.35 tcp port 443 unreachable, length 434
18:44:45.012082 veth6ea24c9 Out IP 10.100.200.5 > 192.168.1.1: ICMP 104.16.27.35 tcp port 443 unreachable, length 434

Following the build process with strace I see TCP connects to registry.yarnpkg.com like

connect(18, {sa_family=AF_INET, sin_port=htons(443), sin_addr=inet_addr("104.16.25.35")}, 16) = -1 EINPROGRESS

Is there a trick to convince yarn (or strapi?) to not do these useless things when a proxy is in operation? In environments without a proxy it's a matter of seconds to build an image.

Marc0
  • 1
  • 1

0 Answers0