K Split X
K Split X

Reputation: 4757

Docker container to use same Nexus volume?

I run the following:

mkdir /some/dir/nexus-data && chown -R 200 /some/dir/nexus-data
chown -R 200 /Users/user.name/dockerVolume/nexus
docker run -d -p 8081:8081 --name nexus -v /some/dir/nexus-data:/nexus-data sonatype/nexus3

Now lets say I upload an artifact to Nexus, and stop the nexus container.

If I want another Nexus container open, on port 8082, what Docker command do I run such that it uses the same volume as on port 8081 (so when I run this container, it already contains the artifact that I uploaded before)

Basically, I want both Nexus containers to use the same storage, so that if I upload an artifact to one port, the other port will also have it.

I ran this command, but it didn't seem to work:

docker run --name=nexus2 -p 8082:8081 --volumes-from nexus sonatype/nexus3

Upvotes: 1

Views: 1969

Answers (1)

Jack Gore
Jack Gore

Reputation: 4252

Bind mounts which is what you're using as a "volume" has limited functionality as compared to an explicit Docker volume.

I believe the --volumes-from flag only works with volumes managed by Docker.

In order to share the volume between containers with this flag you can have docker create a volume for you with your run command.

Example:

$ docker run -d -p 8081:8081 --name nexus -v nexus-volume:/nexus-data sonatype/nexus3

The above command will create a Docker managed volume for you with the name nexus-volume. You can view the details of the created volume with the command $ docker volume inspect nexus-volume.

Now when you want to run a second container with the same volume you can use the --volumes-from command as you desire.

So doing:

$ docker run --name=nexus2 -p 8082:8081 --volumes-from nexus sonatype/nexus3

Should give you your desired behaviour.

Upvotes: 1

Related Questions