码头建设+私人NPM(+私人码头中心) [英] docker build + private NPM (+ private docker hub)
问题描述
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
):
- 登录到您的私人npm注册表您要用于docker的用户
- 复制生成的
.npmrc
文件 - 创建一个
Dockerfile
,可以适当地复制.npmrc
文件。 - 使所有的node.js / io.js容器
FROM你/ iojs
和你很好去。 - log in to your private npm registry with the user you want to use for docker
- copy the
.npmrc
file that this generates - create a
Dockerfile
that copies the.npmrc
file appropriately. - Make all your node.js/io.js containers
FROM you/iojs
and you're good to go.
示例 .npmrc
:
registr y = https://npm.mydomain.com/
username = dockerUser
email = docker@mydomain.com
strict-ssl = false
always-auth = true
//npm.mydomain.com/:_authToken=\"someAuthToken
这是我的 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]
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
):
Example .npmrc
:
registry=https://npm.mydomain.com/
username=dockerUser
email=docker@mydomain.com
strict-ssl=false
always-auth=true
//npm.mydomain.com/:_authToken="someAuthToken"
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" ]
这篇关于码头建设+私人NPM(+私人码头中心)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!