码头建设+私人NPM(+私人码头中心) [英] docker build + private NPM (+ private docker hub)

查看:264
本文介绍了码头建设+私人NPM(+私人码头中心)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Docker容器中运行的应用程序。它需要公司的私有NPM注册表(Sinopia)中的一些私有模块,并且访问这些模块需要用户认证。 Docker文件是 FROM iojs:latest



我尝试过:



1)在项目根目录下创建一个.npmrc文件,这实际上没有区别,npm似乎忽略它
2)使用env变量 NPM_CONFIG_REGISTRY NPM_CONFIG_USER 等,但用户没有登录。



本质上,我似乎有没有办法在 docker build 进程中验证用户。我希望有人可能已经遇到这个问题(似乎是一个明显的问题),并且将有一个很好的解决方法。



(顶一下,我使用Docker Hub上的自动构建(触发推送),以便我们的服务器可以使用预构建的映像访问私有Docker注册表。)



有很好的方法以下任一项:
1)在构建时注入NPM的凭据(所以我不必将凭据提交给我的Docker文件)OR
2)以另一种方式,我没有想到

解决方案

我发现一个有点优雅的ish解决方案为你的node.js / io.js创建一个基本的图像容器( you / iojs ):


  1. 登录到您的私人npm注册表您要用于docker的用户

  2. 复制生成的 .npmrc 文件



    1. 示例 .npmrc

        registr y = https://npm.mydomain.com/ 
      username = dockerUser
      email = docker@mydomain.com
      strict-ssl = false
      always-auth = true
      //npm.mydomain.com/:_authToken=\"someAuthToken




      1. 创建一个 Dockerfile ,可以适当地复制 .npmrc 文件。

      这是我的 Dockerfile (根据 iojs:onbuild ):

        FROM iojs:2.2.1 

      维护者YourSelf

      #从图像中排除NPM缓存
      VOLUME /root/.npm

      #创建应用程序目录
      RUN mkdir -p / usr / src / app
      WORKDIR / usr / src / app

      #复制npm配置
      COPY .npmrc /root/.npmrc

      #安装应用程序
      ONBUILD COPY包.json / usr / src / app /
      ONBUILD RUN npm install
      ONBUILD COPY。 / usr / src / app

      #运行
      CMD [npm,start]




      1. 使所有的node.js / io.js容器 FROM你/ iojs 和你很好去。


      I have an application which runs in a Docker container. It requires some private modules from the company's private NPM registry (Sinopia), and accessing these requires user authentication. The Dockerfile is FROM iojs:latest.

      I have tried:

      1) creating an .npmrc file in the project root, this actually makes no difference and npm seems to ignore it 2) using env variables for NPM_CONFIG_REGISTRY, NPM_CONFIG_USER etc., but the user doesn't log in.

      Essentially, I seem to have no way of authenticating the user within the docker build process. I was hoping that someone might have run into this problem already (seems like an obvious enough issue) and would have a good way of solving it.

      (To top it off, I'm using Automated Builds on Docker Hub (triggered on push) so that our servers can access a private Docker registry with the prebuilt images.)

      Are there good ways of either: 1) injecting credentials for NPM at build time (so I don't have to commit credentials to my Dockerfile) OR 2) doing this another way that I haven't thought of ?

      解决方案

      I found a somewhat elegant-ish solution in creating a base image for your node.js / io.js containers (you/iojs):

      1. log in to your private npm registry with the user you want to use for docker
      2. copy the .npmrc file that this generates

      Example .npmrc:

      registry=https://npm.mydomain.com/
      username=dockerUser
      email=docker@mydomain.com
      strict-ssl=false
      always-auth=true
      //npm.mydomain.com/:_authToken="someAuthToken"
      

      1. create a Dockerfile that copies the .npmrc file appropriately.

      Here's my Dockerfile (based on iojs:onbuild):

      FROM iojs:2.2.1
      
      MAINTAINER YourSelf
      
      # Exclude the NPM cache from the image
      VOLUME /root/.npm
      
      # Create the app directory
      RUN mkdir -p /usr/src/app
      WORKDIR /usr/src/app
      
      # Copy npm config
      COPY .npmrc /root/.npmrc
      
      # Install app
      ONBUILD COPY package.json /usr/src/app/
      ONBUILD RUN npm install
      ONBUILD COPY . /usr/src/app
      
      # Run
      CMD [ "npm", "start" ]
      

      1. Make all your node.js/io.js containers FROM you/iojs and you're good to go.

      这篇关于码头建设+私人NPM(+私人码头中心)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆