2018-01-08 20:45:03 +01:00
---
id: docker
title: Docker
---
2018-05-06 09:12:13 +02:00
< div class = "docker-count" >
![alt Docker Pulls Count ](http://dockeri.co/image/verdaccio/verdaccio "Docker Pulls Count" )
< / div >
2018-07-06 07:11:59 +02:00
要下载(pull)最新的预先-创建的[docker镜像](https://hub.docker.com/r/verdaccio/verdaccio/):
2018-01-08 20:45:03 +01:00
2018-01-21 00:04:36 +01:00
```bash
docker pull verdaccio/verdaccio
```
2018-01-08 20:45:03 +01:00
2018-05-08 21:16:02 +02:00
![Docker pull ](/svg/docker_verdaccio.gif )
2018-05-06 09:12:13 +02:00
2018-07-06 07:11:59 +02:00
## 标记版本
2018-01-08 20:45:03 +01:00
2018-07-06 07:11:59 +02:00
自版本`v2.x`开始,您可以通过[标签](https://hub.docker.com/r/verdaccio/verdaccio/tags/)来下载(pull)docker镜像, 具体操作如下:
2018-01-08 20:45:03 +01:00
2018-07-06 07:11:59 +02:00
对于主版本:
2018-01-08 20:45:03 +01:00
```bash
2018-05-31 10:55:20 +02:00
docker pull verdaccio/verdaccio:3
2018-01-08 20:45:03 +01:00
```
2018-07-06 07:11:59 +02:00
对于次版本:
2018-01-08 20:45:03 +01:00
```bash
2018-05-31 10:55:20 +02:00
docker pull verdaccio/verdaccio:3.0
2018-01-08 20:45:03 +01:00
```
2018-07-06 07:11:59 +02:00
对于特定(补丁)版本:
2018-01-08 20:45:03 +01:00
```bash
2018-05-31 10:55:20 +02:00
docker pull verdaccio/verdaccio:3.0.1
2018-01-08 20:45:03 +01:00
```
2018-07-06 07:11:59 +02:00
下一个主版本将使用 `beta` (主分支)版本。
2018-01-08 20:45:03 +01:00
```bash
docker pull verdaccio/verdaccio:beta
```
2018-07-06 07:11:59 +02:00
> 如果您对标签列表感兴趣,[ 请访问 Docker 网站枢纽](https://hub.docker.com/r/verdaccio/verdaccio/tags/)。
2018-01-21 00:04:36 +01:00
2018-07-06 07:11:59 +02:00
## 用Docker运行verdaccio
2018-01-08 20:45:03 +01:00
2018-07-06 07:11:59 +02:00
要运行docker 容器:
2018-01-08 20:45:03 +01:00
```bash
docker run -it --rm --name verdaccio -p 4873:4873 verdaccio/verdaccio
```
2018-07-06 07:11:59 +02:00
最后一个参数定义要使用的镜像。如果您还没有试的话, 上面的代码将从dockerhub里下载(pull) 最新的预先创建的镜像。
2018-01-08 20:45:03 +01:00
2018-07-06 07:11:59 +02:00
如果您已经用 `verdaccio` 作为最后参数[在本地创建一个镜像](#build-your-own-docker-image)。
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
You can use `-v` to bind mount `conf` , `storage` and `plugins` to the hosts filesystem:
2018-01-08 20:45:03 +01:00
```bash
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 \
2018-07-21 16:34:10 +02:00
-v $V_PATH/plugins:/verdaccio/plugins \
2018-01-08 20:45:03 +01:00
verdaccio/verdaccio
```
2018-07-17 10:41:31 +02:00
> 请注意: Verdaccio 在容器内是作为non-root 用户端 (uid=100, gid=101) 运行, 如果您使用绑定安装来覆盖默认设置, 您需要确保安装目录是被指定到正确的用户端。 在上面的示例里,您要运行 `sudo chown -R 100:101 /opt/verdaccio`,否则在运行的时候您会得到权限错误提醒。 推荐[使用docker卷( volume)](https://docs.docker.com/storage/volumes/)来替代绑定安装。
2018-03-29 08:09:59 +02:00
2018-07-21 16:34:10 +02:00
### Plugins
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
Plugins can be installed in a separate directory and mounted using Docker or Kubernetes, however make sure you build plugins with native dependencies using the same base image as the Verdaccio Dockerfile.
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
### Docker and custom port configuration
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
Any `host:port` configured in `conf/config.yaml` under `listen` is currently ignored when using docker.
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
If you want to reach verdaccio docker instance under different port, lets say `5000` in your `docker run` command replace `-p 4873:4873` with `-p 5000:4873` .
In case you need to specify which port to listen to **in the docker container** , since version 2.?.? you can do so by providing additional arguments to `docker run` : `--env PORT=5000` This changes which port the docker container exposes and the port verdaccio listens to.
Of course the numbers you give to `-p` paremeter need to match, so assuming you want them to all be the same this is what you could copy, paste and adopt:
2018-01-08 20:45:03 +01:00
```bash
PORT=5000; docker run -it --rm --name verdaccio \
--env PORT -p $PORT:$PORT
verdaccio/verdaccio
```
2018-07-21 16:34:10 +02:00
### Using HTTPS with Docker
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
You can configure the protocol verdaccio is going to listen on, similarly to the port configuration. You have to overwrite the default value("http") of the `PROTOCOL` environment variable to "https", after you specified the certificates in the config.yaml.
2018-01-08 20:45:03 +01:00
```bash
PROTOCOL=https; docker run -it --rm --name verdaccio \
--env PROTOCOL -p 4873:4873
verdaccio/verdaccio
```
2018-07-21 16:34:10 +02:00
### Using docker-compose
2018-01-08 20:45:03 +01:00
2018-07-06 07:11:59 +02:00
1. 获取[docker-compose](https://github.com/docker/compose)的最新版本。
2. 创建并运行容器:
2018-01-08 20:45:03 +01:00
```bash
$ docker-compose up --build
```
2018-07-21 16:34:10 +02:00
You can set the port to use (for both container and host) by prefixing the above command with `PORT=5000` .
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
Docker will generate a named volume in which to store persistent application data. You can use `docker inspect` or `docker volume inspect` to reveal the physical location of the volume and edit the configuration, such as:
2018-01-08 20:45:03 +01:00
$ docker volume inspect verdaccio_verdaccio
[
{
"Name": "verdaccio_verdaccio",
"Driver": "local",
"Mountpoint": "/var/lib/docker/volumes/verdaccio_verdaccio/_data",
"Labels": null,
"Scope": "local"
}
]
2018-07-06 07:11:59 +02:00
## 创建您自己的Docker镜像
2018-01-08 20:45:03 +01:00
```bash
docker build -t verdaccio .
```
2018-07-21 16:34:10 +02:00
There is also an npm script for building the docker image, so you can also do:
2018-01-08 20:45:03 +01:00
```bash
npm run build:docker
```
2018-07-21 16:34:10 +02:00
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` .
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
If you want to use the docker image on a rpi or a compatible device there is also a dockerfile available. To build the docker image for raspberry pi execute:
2018-01-08 20:45:03 +01:00
```bash
npm run build:docker:rpi
```
2018-07-21 16:34:10 +02:00
Please note that for any of the above docker commands you need to have docker installed on your machine and the docker executable should be available on your `$PATH` .
2018-01-08 20:45:03 +01:00
2018-07-06 07:11:59 +02:00
## Docker示例
2018-01-08 20:45:03 +01:00
2018-07-21 16:34:10 +02:00
There is a separate repository that hosts multiple configurations to compose Docker images with `verdaccio` , for instance, as reverse proxy:
2018-01-08 20:45:03 +01:00
2018-04-24 21:52:30 +02:00
< https: / / github . com / verdaccio / docker-examples >
2018-01-21 11:29:14 +01:00
2018-07-06 07:11:59 +02:00
## Docker 自定义创建
2018-01-21 11:29:14 +01:00
* [docker-verdaccio-gitlab ](https://github.com/snics/docker-verdaccio-gitlab )
* [docker-verdaccio ](https://github.com/deployable/docker-verdaccio )
2018-07-06 07:11:59 +02:00
* [docker-verdaccio-s3 ](https://github.com/asynchrony/docker-verdaccio-s3 ) 专用 NPM 容器可以备份到s3
2018-01-21 11:29:14 +01:00
* [docker-verdaccio-ldap ](https://github.com/snadn/docker-verdaccio-ldap )
* [verdaccio-ldap ](https://github.com/nathantreid/verdaccio-ldap )
* [verdaccio-compose-local-bridge ](https://github.com/shingtoli/verdaccio-compose-local-bridge )
* [docker-verdaccio ](https://github.com/Global-Solutions/docker-verdaccio )
* [verdaccio-docker ](https://github.com/idahobean/verdaccio-docker )
* [verdaccio-server ](https://github.com/andru255/verdaccio-server )
2018-07-06 07:11:59 +02:00
* [coldrye-debian-verdaccio ](https://github.com/coldrye-docker/coldrye-debian-verdaccio ) coldrye-debian-nodejs支持的verdaccio docker镜像。