0

I'm running verdaccio locally (through docker) to publish private npm packages. I'm building one of my packages with Dockerfile which has:

RUN npm ci

in it. I'm actually building with docker-compose. I have a .env file to set these args:

        - NPM_CONFIG_REGISTRY
        - NPM_CONFIG_USERNAME
        - NPM_CONFIG_EMAIL
        - NPM_CONFIG_PASSWORD

It is successfully trying to get packages from my local registry but it can't connect.

So my question is - how can I run docker-compose build myservice and have myservice use the locally running instance of verdaccio to pull packages from during the docker build?

EDIT: I'm running on a mac host.

justin
  • 3,357
  • 1
  • 23
  • 28

1 Answers1

2

It seems to be working by adding a network: host entry under the service's build:

    build:
      context: ./packages/server
      target: dev
      network: host

NOTE: giving some time to test this before accepting it as an answer (just in case as I've tried a number of other things to get this to work).

justin
  • 3,357
  • 1
  • 23
  • 28
  • 1
    This is rarely necessary, and disables one of the core parts of Docker. Often it's to work around a hard-coded `localhost` somewhere. In the context of Docker for Mac, the magic host name `host.docker.internal` will refer to the physical host system (and host networking often doesn't work as you expect). – David Maze Feb 14 '20 at 12:55
  • @DavidMaze thanks! I was able to remove the `network: host` in the build config and use the magic host name in my .env file: `NPM_CONFIG_REGISTRY=http://host.docker.internal:4873/`. The build is working as before. Could you add this as an answer? Do you know of a reference somewhere to "magic" host names for other host OSes? Or will `host.docker.internal` work elsewhere? – justin Feb 14 '20 at 22:02