Table of contents
- 1οΈβ£ Install Docker π³
- 2οΈβ£ Add Nexus URL to Insecure Registries π
- 3οΈβ£ Set Up Nexus Using a Docker Container π οΈ
- 4οΈβ£ Create a Docker Hosted Repository in Nexus ποΈ
- 5οΈβ£ Enable Docker Bearer Token Authentication π
- 6οΈβ£ Log In to the Private Docker Registry π
- 7οΈβ£ Tagging an Image π·οΈ
- 8οΈβ£ Push an Image to the Private Repository π€
- 9οΈβ£ Pull a Public Image, Tag, and Push to Nexus π³οΈ
- π Remove Local Image and Pull from Private Registry ποΈβ¬οΈ
Managing your own private Docker registry can be a game-changer for secure, fast, and efficient container deployments. In this blog, weβll guide you through setting up a private Docker registry using Nexus step by step. Follow along to ensure your registry is up and running smoothly! π
1οΈβ£ Install Docker π³
Before we dive in, ensure Docker is installed on your machine. Follow the instructions for your operating system on the Docker official site.
Verify installation:
sudo apt install docker.io
docker --version
2οΈβ£ Add Nexus URL to Insecure Registries π
If you're hosting Nexus without SSL (not recommended for production):
Locate Dockerβs
daemon.json
file (usually in/etc/docker/daemon.json
on Linux orC:\ProgramData\docker\config\daemon.json
on Windows).Add your Nexus server URL under
insecure-registries
:{ "insecure-registries": ["<your-nexus-url>:<port>"] }
Restart Docker to apply changes:
sudo systemctl restart docker # Linux
3οΈβ£ Set Up Nexus Using a Docker Container π οΈ
Run Nexus as a Docker container:
docker run -d -p 8081:8081 -p 5000:5000 --name nexus sonatype/nexus3
Access Nexus via your browser at http://<your-server-ip>:8081
. Log in using the default credentials:
Username:
admin
Password: Found in the file
/nexus-data/admin.password
inside the container.
4οΈβ£ Create a Docker Hosted Repository in Nexus ποΈ
Navigate to Repositories in the Nexus UI.
Click Create repository β Select Docker (hosted).
Configure the following:
Name:
docker-private
HTTP Port: Specify a port (e.g.,
5000
).
Save the repository.
5οΈβ£ Enable Docker Bearer Token Authentication π
Go to Administration β Security β Realms.
Activate Docker Bearer Token Realm by moving it to the active realms list.
Save the settings.
6οΈβ£ Log In to the Private Docker Registry π
Authenticate with the private registry:
bashCopy codedocker login <your-nexus-url>:<port>
Provide your Nexus credentials.
7οΈβ£ Tagging an Image π·οΈ
Letβs tag a local Docker image for your private registry:
docker tag <local-image>:<tag> <your-nexus-url>:<port>/<repo-name>/<image_name>:<tag>
For example:
docker tag nginx:latest localhost:5000/docker-private/nginx-latest
8οΈβ£ Push an Image to the Private Repository π€
Push the tagged image to your private registry:
docker push <your-nexus-url>:<port>/<repo-name>:<tag>
Example:
docker push localhost:5000/docker-private:nginx-latest
9οΈβ£ Pull a Public Image, Tag, and Push to Nexus π³οΈ
Pull a public image from Docker Hub:
docker pull busybox:latest
Tag it for your private registry:
docker tag busybox:latest localhost:5000/docker-private/busybox:latest
Push the tagged image:
docker push localhost:5000/docker-private/busybox:latest
π Remove Local Image and Pull from Private Registry ποΈβ¬οΈ
Remove the image from your local machine:
docker rmi <your-nexus-url>:<port>/<repo-name>:<tag>
Example:
docker rmi localhost:5000/docker-private:nginx-latest
Pull the image from your private registry to verify:
docker pull <your-nexus-url>:<port>/<repo-name>:<tag>
Example:
docker pull localhost:5000/docker-private:nginx-latest
π All Set!
You now have a fully functional private Docker registry hosted on Nexus. You can securely push, pull, and manage Docker images in your repository. π Happy containerizing! π’