How can I connect to my Verdaccio service launched as docker container from another docker container?

844 views Asked by At

I am trying to build an npm repository which will be used on an offline system. My idea is to build a ready docker container, which will already contain all the packages needed for a given project - downloading the packages will be based on the package.json file.

To implement my idea, I need to run server verdaccio on one container, then the other container will run the npm install command, thanks to which the appropriate files with ready npm packages will be generated.

However, I cannot cope with waiting for the launch of the first container. So far I have tried to use the wait-for.sh and wait-for.sh scripts (https://docs.docker.com/compose/startup-order/), but they are not able to connect to the given address.

P.S I am using Docker for Windows

docker-compose.yml

version: '3.1'
services:
  listen:
    build: listen
    image: listen-img
    container_name: listen
    environment:
      - VERDACCIO_PORT=4873
    ports:
      - "4873:4873"
  download:
    build: download
    image: download-img
    container_name: download
    depends_on:
      - listen
networks:
  node-network:
    driver: bridge

server dockerfile

FROM verdaccio/verdaccio:4

'npm install trigger' docker file

FROM node:15.3.0-alpine3.10
WORKDIR /usr/src/cached-npm
COPY package.json .
COPY wait-for.sh .
COPY /config/htpasswd /verdaccio/conf/htpasswd
USER root
RUN npm set registry http://host.docker.internal:4873
RUN chmod +x /usr/src/cached-npm/wait-for.sh
RUN /usr/src/cached-npm/wait-for.sh host.docker.internal:4873 -- echo "Listen is up"
RUN npm install

Is there something like a lack of shared ports missing from my solution, or are there other issues that are causing my approach to fail?

1

There are 1 answers

0
Swierszczu On

It turned out that the problem was to mix up two processes - building and launching the appropriate container. In my solution so far, I wanted to build both containers at the same time, while one of them needed an already running instance of the first to be built.