
Provision Nexus Repository Manager (NXRM) Docker container.
All scripts are written in Bash, and the Nexus REST API calls are made with curl. Check the provision/entrypoint.sh to learn more about the provisioning process.
$HOME/.docker/config.json or the Docker Engine, and then restart the Docker Daemon.
"insecure-registries": [
"localhost:8081"
],

The provisioning script provision/entrypoint.sh performs the following tasks
/nexus-data/admin.password to adminlocalhost:8081 with READ permissionslocalhost:8081docker-hub - DockerHubdocker-ecrpublic - AWS ECR Publicdocker-group - The above Docker repositories are members of this Docker group# ulimit - https://help.sonatype.com/repomanager3/installation/system-requirements#SystemRequirements-Docker
# 8081 - Nexus
# 8082 - docker-group
docker run -d \
--ulimit nofile=65536:65536 \
-p 8081:8081 \
-p 8082:8082 \
--name nexus "unfor19/nexus-ops"
Nexus's Repository will serve as a "cache server", here's the logic -
docker pull goes through localhost:8082/repository/docker-group and gets the and then redirected to the relevant docker-proxy.
http://localhost:8081/repository/docker-hub/v2/http://localhost:8081/repository/docker-ecrpublic/v2/localhost:8082/nginx to nginx, so the references in your Dockerfile can remain nginx.This is the exact same process that was done in the Quick Start section, only now we're going to do it manually in the UI. The purpose of this section is to help Nexus newbies (like me) to get familiar with the UI.
For the sake of simplicity, I won't be using Docker volumes for Persistent Data. The nexus-data is generated at the top layer of Nexus's container, so if the container is removed (not stopped), all the data in nexus-data is lost, including the Docker images.
NEXUS_VERSION="3.30.1" && \
# ulimit - https://help.sonatype.com/repomanager3/installation/system-requirements#SystemRequirements-Docker
# 8081 - Nexus
# 8082 - docker-group
docker run -d \
--ulimit nofile=65536:65536 \
-p 8081:8081 \
-p 8082:8082 \
--name nexus "sonatype/nexus3:${NEXUS_VERSION}"
nexus and execute
cat /nexus-data/admin.password; echo # the extra echo makes it easier to copy-paste
# Example:
# e9d3c296-c89a-41b3-bc44-1484c59c9f05
adminfrom-previous-stepadmin and Enable anonymous accessServer Administration (Cogwheel) > Repositories > Create DockerHub repository
docker-hubhttps://registry-1.docker.io(Optional) Server Administration (Cogwheel) > Repositories > Create AWS ECR Public repository
docker-ecrhttps://public.ecr.aws
aws ecr-public get-login-password --region us-east-1 | docker login --username AWS --password-stdin public.ecr.aws
Server Administration (Cogwheel) > Repositories > Create repository
docker-group8082 - Images are pulled from http://localhost:8082docker-hubdocker-ecrRealms > Add Docker Bearer Token Realm - Enables Anonymous Pulls
localhost:8082
docker pull localhost:8082/unfor19/alpine-ci:latest && \
docker pull localhost:8082/ubuntu:20.04
docker.io or omit the prefix (like I did), that will mitigate the need to rename images to localhost:8082
docker tag localhost:8082/unfor19/alpine-ci:latest unfor19/alpine-ci:latest && \
docker tag localhost:8082/ubuntu:20.04 ubuntu:20.04
docker build - build the application; the Docker Daemon already pulled the required images to build the app.
git clone https://github.com/unfor19/nexus-ops.git
cd nexus-ops
docker build -f Dockerfile.example -t unfor19/nexus-ops:example .
test image
docker run --rm unfor19/nexus-ops:example
# Miacis, the primitive ancestor of cats, was a small, tree-living creature of the late Eocene period, some 45 to 50 million years ago.
# ^^ A random cat fact for each build
I've added the GitHub Action - docker-release.yml. If you check it out, you'll see the following code snippet
jobs:
docker:
name: docker
runs-on: linux-self-hosted # <-- A label that I chose
As implied from the label self-hosted, I intend to run this workflow on my local machine. Adding your local machine as a self-hosted runner is quite simple.
Enter any additional labels (ex. label-1,label-2): linux-self-hosted
~/actions-runner $ ./config.sh --url https://github.com/unfor19/nexus-ops --token YOUR_TOKEN
...
√ Settings Saved.
~/actions-runner $ ./run.sh
√ Connected to GitHub
2021-06-01 21:18:04Z: Listening for Jobs
Go on and initiate a workflow; add a file, commit and push.
touch some-file && \
git add some-file && \
git commit -m "added some file" && \
git push
So far, the examples showed how to use DockerHub, though the process is the same for AWS ECR or any other container registry.
Pull from DockerHub - nginx:1.19-alpine
docker pull localhost:8082/nginx:1.19-alpine
Pull from ECR - nginx/nginx:1.19-alpine
docker pull localhost:8082/nginx/nginx:1.19-alpine
But what happens if both repositories hold images with the same tags? owner/repository:tag
We'll use bitnami/kubectl:latest which is named the same both in DockerHub and AWS ECR Public
docker pull localhost:8082/bitnami/kubectl:latest
Navigate to http://localhost:8081/service/rest/repository/browse/docker-hub/v2/bitnami/kubectl/tags/, as the link implies, the image was pulled from DockerHub.
To change this behavior, go to the docker-group's settings and change the order of Members

After changing the order of Members -

Remove the existing image from the local Docker Daemon cache
docker rmi localhost:8082/bitnami/kubectl
Pull the image again; this time, it will be from ECR
docker pull localhost:8082/bitnami/kubectl
Check results at http://localhost:8081/service/rest/repository/browse/docker-ecr/v2/bitnami/kubectl/tags/
docker build -t unfor19/nexus-ops .
docker run -d -it --name nexus -p 8081:8081 -p 8082:8082 -v "$PWD"/:/code/ unfor19/nexus-ops
docker exec -it nexus --workdir="/code/provision" bash
entrypoint.sh in local IDE (VSCode, PyCharm, etc.), and then execute the code in the container
# Exploring current dir /code/provision
bash-4.4$ ls
entrypoint.sh repositories wait_for_endpoints.sh
# After changing the code
# Execute entrypoint.sh
bash-4.4$ ./entrypoint.sh
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Healthy endpoint - http://localhost:8081/service/rest/v1/status/writable
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Nexus API is ready to receive requests
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Password was set
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Repository exists - proxy docker-hub
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Repository exists - proxy docker-ecrpublic
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Repository exists - group docker-group
[LOG] Sun Jun 6 22:58:46 UTC 2021 :: Finished executing - /nexus-data/nexus-ops/entrypoint.sh
The easiest way to get familiar with Nexus's REST API, is to run Nexus locally and check the API page http://localhost:8081/#admin/system/api.
From there, you can execute commands with Swagger UI, and get the relevant curl commands. The following example demonstrates how I learned about the [GET] repositories/docker/proxy/{repositoryName} API.

The provided curl commands do not include -u admin:admin, so make sure you add this argument when you use curl. Here's an example of a curl command
curl -u admin:admin -X GET "http://localhost:8081/service/rest/v1/repositories/docker/proxy/docker-ecrpublic" -H "accept: application/json"
Tip: It's best to invoke the
curlcommands within the runningnexuscontainer (docker exec), and not from your local machine. That is becauseentrypoint.shis running as part of the container's startup, so it's best to test this file as if the container is running it, and not some other machine (like your local machine).
--pull missing). This helps to avoid hitting DockerHub for each pull, though it means you need to prepare a list of images that should be pulled.Created and maintained by Meir Gabay
This project is licensed under the MIT License - see the LICENSE file for details
Content type
Image
Digest
Size
327.5 MB
Last updated
over 5 years ago
docker pull unfor19/nexus-ops