I'm encountering a problem with Docker volumes while attempting to preserve Nexus data within a container
I have a Docker image containing Maven and npm artifacts, with all the data stored in the /nexus-data directory. On a remote machine, I've set up a Nexus container and published all Maven and npm artifacts. Then, I'm using a script to create an image with this data, as described in the provided Dockerfile.
# Use the official Nexus base image
FROM sonatype/nexus3
# Copy the Nexus data from the host to the container's data directory
COPY nexus-data /nexus-data
# Change permission
USER root
RUN chown -R nexus:nexus /nexus-data
USER nexus
# Set the desired permissions on the Nexus data directory
COPY --chown=nexus:nexus nexus-data /nexus-data
# Start Nexus on port 8079
EXPOSE 8079
# Start Nexus
CMD ["sh", "-c", "/opt/sonatype/start-nexus-repository-manager.sh"]
However, when I try to use bind volumes to preserve the Nexus data, it doesn't work as expected. The data doesn't persist, and it seems like the container starts fresh without any data. Here's the command I'm using:
mkdir /data
chown -R 200:200 /data
docker run -d -p 8081:8081 -v /data:/nexus-data <image>
When I am not using any data volumes in container creation, it is working as expected.
I have read somewhere that if the host machines volume directory is empty, it will overrides the container's data. But I needs to use the data volumes as my nexus image will be recreates very often.
I expected the Nexus data to be preserved and accessible within the container when using bind volumes.