Nexus3 Default Install

The default installation will serve as a simple out-of-the-box version controlled docker image of Nexus3. Generally speaking, when managing third party applications this is a normal starting point to get the application up and running. The Nexus3 docker image has a few minor changes when comparing to the official nexus3 Dockerfile available at https://github.com/sonatype/docker-nexus3/blob/master/Dockerfile.

labseednexus-default
version: '3.8'

services:
    nexus:
      image: seed/sonatype/nexus3-default:1.0.0
      build: .
FROM seed/java/openjdk-8:1.0.0

ARG CONTAINER_UID=2001
ARG CONTAINER_GID=2001
ARG CONTAINER_USER=nexus
ARG CONTAINER_GROUP=nexus

RUN groupadd -g ${CONTAINER_GID} ${CONTAINER_GROUP} \
    && useradd -d /home/${CONTAINER_USER} -u ${CONTAINER_UID} -g ${CONTAINER_GROUP} -m -s /bin/bash ${CONTAINER_USER}

RUN mkdir -p /opt/sonatype/nexus /opt/sonatype/sonatype-work/nexus3 \
    && ln -s /opt/sonatype/sonatype-work/nexus3 /nexus-data \
    && chown -R nexus:nexus /opt/sonatype /nexus-data

ARG NEXUS_VERSION=3.41.0-01
ARG NEXUS_CHECKSUM=ce265e627a665f9e833bf9c6e15a58c739882eb753863062f9e42e83e6f0d844

RUN curl -fsSL https://download.sonatype.com/nexus/3/nexus-${NEXUS_VERSION}-unix.tar.gz -o /tmp/nexus-${NEXUS_VERSION}-unix.tar.gz \
    && sha256sum /tmp/nexus-${NEXUS_VERSION}-unix.tar.gz \
    && echo "${NEXUS_CHECKSUM}  /tmp/nexus-${NEXUS_VERSION}-unix.tar.gz" | sha256sum -c - \
    && tar -xvzf /tmp/nexus-${NEXUS_VERSION}-unix.tar.gz --strip-components=1 -C /opt/sonatype/nexus \
    && rm -rf /tmp/*

USER nexus

CMD ["/opt/sonatype/nexus/bin/nexus","run"]

A couple of notes worth pointing out, VOLUME statements are a bit of a thing of the past and can easily be skipped as we are in full control of image source and usages, plus we are going to be in charge of controlling volumes via the compose files, so we want to avoid volumes being created behind the scenes. The same can be said about EXPOSE; while it may be nice to see it during inspect when doing development of public images, when controlling it yourself there is no need, especially as you run containers in development or production with full control of network and ports.

Building and Running

Build the image with the respective build compose file.

docker-compose -f seed/nexus-default/docker-compose.yml build

Running it will be done with build images and their own run compose file. While both building and running can be combined, we isolate the two distinct steps, with a build compose file in the Dockerfile folder and run compose files generally located on the root or elsewhere.

labcomposed
version: '3.8'

services:
  nexus:
    image: seed/sonatype/nexus3-default:1.0.0
    ports:
      - 8081:8081
    volumes:
      - nexus-data-default:/nexus-data
volumes:
  nexus-data-default:
    name: nexus-data-default
version: '3.8'

services:
  nexus:
    image: seed/sonatype/nexus3-default:1.0.0
    ports:
      - 8081:8081
    volumes:
      - ./nexus-data-default:/nexus-data

Run it with default.

docker-compose -f composed/docker-compose-seed-default.yml up

Once started, you can access your docker Nexus3 via http://localhost:8081. The default installation will auto-generate a password and store it at /opt/sonatype/sonatype-work/nexus3/admin.password. As we mapped this to a docker volume you may not be able to access the file easily. This is where shell access into your container is beneficial, or direct access to the volume on your host. Alternatively, you can start the container with a mounted volume instead to write the content to your local file system.

docker-compose -f composed/docker-compose-seed-default-mounted.yml up

While this provides a good starting point to get Nexus3, as a third party application, up and running via your own version controlled docker images, it does require user interaction which is the next element to remove, so any configuration can be automated.