Skip to main content

Docker

alt Docker Pulls Count

要下载(pull)最新的预先-创建的docker镜像

docker pull verdaccio/verdaccio

Docker pull

标记版本

自版本v2.x开始,您可以通过标签来下载(pull)docker镜像,具体操作如下:

对于主版本:

docker pull verdaccio/verdaccio:4

对于次版本:

docker pull verdaccio/verdaccio:4.0

对于特定(补丁)版本:

docker pull verdaccio/verdaccio:4.0.0

如果您对标签列表感兴趣, 请访问 Docker 网站枢纽

Running Verdaccio using Docker

要运行docker 容器:

docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio

The last argument defines which image to use. The last argument defines which image to use. The above line will pull the latest prebuilt image from dockerhub, if you haven't done that already.

如果您已经用 verdaccio作为最后参数在本地创建一个镜像

您可以用 -v来绑定安装 conf, storageplugins到主机文件系统中:

V_PATH=/path/for/verdaccio; docker run -it --rm --name verdaccio \
-p 4873:4873 \
-v $V_PATH/conf:/verdaccio/conf \
-v $V_PATH/storage:/verdaccio/storage \
-v $V_PATH/plugins:/verdaccio/plugins \
verdaccio/verdaccio

Note: Verdaccio runs as a non-root user (uid=10001) inside the container, if you use bind mount to override default, you need to make sure the mount directory is assigned to the right user. In above example, you need to run sudo chown -R 10001:65533 /opt/verdaccio otherwise you will get permission errors at runtime. 推荐使用docker卷(volume)来替代绑定安装。 Note: Verdaccio runs as a non-root user (uid=10001) inside the container, if you use bind mount to override default, you need to make sure the mount directory is assigned to the right user. In above example, you need to run sudo chown -R 10001:65533 /path/for/verdaccio otherwise you will get permission errors at runtime. Use docker volume is recommended over using bind mount.

Verdaccio 4 provides a new set of environment variables to modify either permissions, port or http protocol. Here the complete list: Here the complete list:

属性default描述
VERDACCIO_APPDIR/opt/verdaccio-buildthe docker working directory
VERDACCIO_USER_NAMEverdacciothe system user
VERDACCIO_USER_UID10001the user id being used to apply folder permissions
VERDACCIO_PORT4873the verdaccio port
VERDACCIO_PROTOCOLhttpthe default http protocol

SELinux

If SELinux is enforced in your system, the directories to be bind-mounted in the container need to be relabeled. Otherwise verdaccio will be forbidden from reading those files.

 fatal--- cannot open config file /verdaccio/conf/config.yaml: Error: CONFIG: it does not look like a valid config file

If verdaccio can't read files on a bind-mounted directory and you are unsure, please check /var/log/audit/audit.log to confirm that it's a SELinux issue. In this example, the error above produced the following AVC denial.

type=AVC msg=audit(1606833420.789:9331): avc:  denied  { read } for  pid=1251782 comm="node" name="config.yaml" dev="dm-2" ino=8178250 scontext=system_u:system_r:container_t:s0:c32,c258 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0

chcon can change the labels of shared files and directories. To make a directory accessible to containers, change the directory type to container_file_t.

$ chcon -Rt container_file_t ./conf

If you want to make the directory accessible only to a specific container, use chcat to specify a matching SELinux category.

An alternative solution is to use z and Z flags. To add the z flag to the mountpoint ./conf:/verdaccio/conf simply change it to ./conf:/verdaccio/conf:z. The z flag relabels the directory and makes it accessible by every container while the Z flags relables the directory and makes it accessible only to that specific container. However using these flags is dangerous. A small configuration mistake, like mounting /home/user or /var can mess up the labels on those directories and make the system unbootable.

插件

插件可以在单独的目录里安装,并用Docker或者Kubernetes挂载,然而,请确保使用与Verdaccio Dockerfile相同的基镜像的本地依赖项来创建插件。

FROM verdaccio/verdaccio

USER root

ENV NODE_ENV=production

RUN npm i && npm install verdaccio-s3-storage

USER verdaccio

Docker和自定义端口配置

Any host:port configured in conf/config.yaml under listen is currently ignored when using docker.

还有一个创建docker image(镜像)的npm脚本,因此您还可以执行以下操作:

V_PATH=/path/for/verdaccio; docker run -it --rm --name verdaccio \
-e "VERDACCIO_PORT=8080" -p 8080:8080 \
verdaccio/verdaccio

Of course the numbers you give to the -p parameter need to match.

在Docker中使用HTTPS

您可以配置 verdaccio 要监听的协议,类似于端口配置。 在 config.yaml里指定证书后,您必须用"https"覆盖PROTOCOL 环境变量中的默认值("http")。

docker run -it --rm --name verdaccio \
--env "VERDACCIO_PROTOCOL=https" -p 4873:4873
verdaccio/verdaccio

使用docker-compose

  1. 获取docker-compose的最新版本。
  2. 创建并运行容器:
$ docker-compose up --build

You can set the port to use (for both container and host) by prefixing the above command with VERDACCIO_PORT=5000.

version: '3.1'

services:
verdaccio:
image: verdaccio/verdaccio
container_name: "verdaccio"
networks:
- node-network
environment:
- VERDACCIO_PORT=4873
ports:
- "4873:4873"
volumes:
- "./storage:/verdaccio/storage"
- "./config:/verdaccio/conf"
- "./plugins:/verdaccio/plugins"
networks:
node-network:
driver: bridge

Docker将生成一个named volume(命名卷),它用于存储持久化应用程序数据。 您可以使用docker inspect 或者 docker volume inspect 来查看此volume(卷)的物理位置并编辑配置,比如:

$ docker volume inspect verdaccio_verdaccio
[
{
"Name": "verdaccio_verdaccio",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/verdaccio_verdaccio/_data",
"Labels": null,
"Scope": "local"
}
]

创建您自己的Docker镜像

docker build -t verdaccio .

请注意:第一个镜像的创建要花费几分钟时间,因为它需要运行npm install,而且,当您任何时候更改任何没有列在.dockerignore里的文件,它也需要运行那么长的时间。

yarn run build:docker

Note: The first build takes some minutes to build because it needs to run npm install, and it will take that long again whenever you change any file that is not listed in .dockerignore.

请注意,您需要在您的机器上安装 docker 来执行以上任何docker命令, docker 可执行程序应该在您的$PATH里。

Docker示例

有个分开的 repository(资源库)承载多个配置来用 verdaccio生成Docker镜像,例如,reverse proxy(反向代理服务器):

https://github.com/verdaccio/docker-examples

Docker 自定义创建

If you have made an image based on Verdaccio, feel free to add it to this list.