NewLearner
NewLearner

Reputation: 41

Docker image mounting the existing data volume for nexus

  1. I have added new repositories on nexus 3.17. There is no data, just repos.
  2. Created .bak files
  3. Created a docker image for nexus(call it 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. 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 run -d -p 8081:8081 --name nexus -v <local-docker-volume>:/nexus-data newimage

The Dockerfile I use to create an image

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

Any idea what I am doing wrong?

p.s: let me know if I am not clear.

Upvotes: 1

Views: 1443

Answers (1)

akazuko
akazuko

Reputation: 1394

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).

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. 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.

To address the issue, you can do the following:

  • add the data to a different location in dockerfile say 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/

Upvotes: 1

Related Questions