Docker Alpine Node takes a long time

Hi,

I did a basic docker setup with node and mongo. But running
docker compose up
Takes many minutes. This is probably a mistake I guess?

Any ideas what could cause something like this?

This is my Dockerfile

FROM node:alpine

WORKDIR /usr/src/app

COPY package*.json .

COPY . .

RUN npm ci

RUN npm run build

CMD ["npm", "start"]

and this is my docker-compose.yml

version: "3.9"

services:
  # mongo db
  mongo_db:
    container_name: db_gag_container
    image: mongo:latest
    restart: always
    volumes:
      - mongo_db:/data/db

  # api gags
  api:
    build: .
    ports:
      - "3000:3000"
    environment:
      PORT: 3000
      MONGODB_URI: mongodb://mongo_db:27017
      DB_NAME: gag
      NAME: gag
    depends_on:
      - mongo_db

volumes:
  mongo_db: {}

I have a .dockerignore aswell which looks like this:

node_modules

./node_modules

Dockerfile

.dockerignore

docker-compose.yml

This currently output after running docker compose up in the terminal is this

[+] Building 525.5s (2/3)
 => [internal] load build definition from Dockerfile                                                                                                         0.0s
 => => transferring dockerfile: 31B                                                                                                                          0.0s
 => [internal] load .dockerignore                                                                                                                            0.0s
 => => transferring context: 34B                                                                                                                             0.0s
 => [internal] load metadata for docker.io/library/node:alpine                                                                                             525.3s

Good morning,
if you run docker-compose up -d it checks if there is already an image matching the corresponding lines in your docker-compose.yml. If not it fetches it from the registry or (in your case) builds it.
Building an image can take some time depending on the work to be done and the speed of your system and/or your network-connection.
So the next start should be faster as there is already an image available.
If you have changed some things in your code and want to rebuild the image you can run docker-compose build and docker-compose up -d (or docker-compose up -d --build to do all in one).

1 Like

Hi, how many minutes could this take? I am now running docker-compose build and afterward docker-compose up -d.
I mean it should not take an hour, right?
I assume I do not have any issue in my .yml file, but how could I further debug this.

Currently docker desktop on my mac shows that docker can use
6 CPUS
3,5 GB of memory
Swap 1.5GB
Disk Size of 80GB

I agree that 60 minutes is much time to build an image. But depending on the workload (I don’t know your application) it can take some time.

If a Dockerfile is not working as expected I try to reproduce the steps “by hand”. That means (in this case) start an interactive terminal in a container based on node:alpine and reproduce all the steps that are in the Dockerfile. If there is a COPY I use docker copy ... run from another terminal, if there is a RUN ... I run these commands in the container’s shell. Most of the times I was able to find the issue. Sometimes a mandatory library was missing and needed to be installed before, sometimes it was waiting for user’s input…

How long would you say the script should maximum take? In order to say “hey this takes to long”

I’m sorry - I don’t know.
It really depends on the tasks to be done.
I have Dockerfile's that need 5 seconds to be built and others need up to 27 minutes.
Try to recreate the steps from your Dockerfile as mentioned to see which step takes which amount of time or if there are any errormessages or tasks waiting for user-input.

Hi. I have the same problem as you. I waited for 2 3 hours it was still showing load metadata for docker.io/library/node:alpine . Do you know what causes this problem and how to solve it? Very much appreciate your reply. Thanks you