简体   繁体   English

Docker 镜像挂载nexus的现有数据卷

[英]Docker image mounting the existing data volume for nexus

  1. I have added new repositories on nexus 3.17.我在 nexus 3.17 上添加了新的存储库。 There is no data, just repos.没有数据,只有回购。
  2. Created.bak files创建的.bak 文件
  3. Created a docker image for nexus(call it newimage).为 nexus 创建了一个 docker 图像(称为 newimage)。

I have data from the current version(3.3.1) on a volume and I want the data to show up in the new nexus.我在一个卷上有来自当前版本(3.3.1)的数据,我希望数据显示在新的关系中。 When I try below the docker run command and go to nexus, new repositories do not show up, but data is there for old repos.当我尝试在 docker 运行命令和 go 下连接到 nexus 时,没有显示新的存储库,但旧存储库的数据在那里。

docker run -d -p 8081:8081 --name nexus -v <local-docker-volume>:/nexus-data newimage

The Dockerfile I use to create an image我用来创建图像的 Dockerfile

FROM sonatype/nexus3:3.17.0  
COPY path-to-bak-files/*.bak /nexus-data/restore-from-backup/

Any idea what I am doing wrong?知道我做错了什么吗?

ps: let me know if I am not clear. ps:如果我不清楚,请告诉我。

As per your dockerfile you are copying the contents to /nexus-data/restore-from-backup/ but while running the container you are mounting the existing volume on /nexus-data which ends up masking the /nexus-data directory on file system inside the container (where you added the data while image creation).根据您的 dockerfile 您正在将内容复制到/nexus-data/restore-from-backup/但是在运行容器时,您将现有卷安装在/nexus-data上,这最终掩盖了文件系统上的/nexus-data目录在容器内(在创建图像时添加数据的地方)。

Important thing to note in mount operation is that if you mount another disk/share (in this case volume) on an existing directory on your file system(FS), you can't access the dir from your FS anymore.挂载操作中需要注意的重要一点是,如果您在文件系统 (FS) 的现有目录上挂载另一个磁盘/共享(在本例中为卷),则无法再从 FS 访问该目录。 Thus, when you created docker image, you added some files to /nexus-data/restore-from-backup/ but when you mounted volume on /nexus-data, you mounted it over dir in your FS so you can't see files now from your FS.因此,当您创建 docker 映像时,您向 /nexus-data/restore-from-backup/ 添加了一些文件,但是当您在 /nexus-data 上安装卷时,您将其安装在 FS 中的 dir 上,因此您看不到文件现在从你的FS。

To address the issue, you can do the following:要解决此问题,您可以执行以下操作:

  • add the data to a different location in dockerfile say location1将数据添加到 dockerfile 中的不同位置,例如location1
  • create container with volume mount as you are currently doing像您当前所做的那样创建带有卷挂载的容器
  • use entrypoint OR command to copy the files from location1 to /nexus-data/restore-from-backup/使用 entrypoint OR 命令将文件从location1复制到/nexus-data/restore-from-backup/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM