A Docker Registry is a secure repository for Docker container images. In this guide, we will walk you through setting up your own private Docker Registry on an Ubuntu 22.04 server. This is useful for keeping your Docker images private or when working with proprietary software.
Before we begin, ensure you have the following:
```bash mkdir ~/docker-registry cd ~/docker-registry ```
```bash mkdir data ```
```bash nano docker-compose.yml ```
```yaml version: '3' services: registry: image: registry:latest ports: - "5000:5000" environment: REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data volumes: - ./data:/data ```
Save and close the file.
```bash docker-compose up ```
Your Docker Registry container is now running. You can stop it later by pressing `CTRL+C`.
```bash sudo nano /etc/nginx/sites-available/your_domain ```
```nginx location / { # Do not allow connections from older Docker clients if ($http_user_agent ~ "^(docker\/1\.(3|4|5(?!\.[0-9]-dev))|Go ).*$") { return 404; } proxy_pass http://localhost:5000; proxy_set_header Host $http_host; # required for Docker client proxy_set_header X-Real-IP $remote_addr; # pass on real client's IP proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_read_timeout 900; } ```
Save and close the file.
```bash sudo systemctl restart nginx ```
Your NGINX server is now forwarding traffic to your Docker Registry.
```bash sudo apt install apache2-utils -y ```
```bash mkdir ~/docker-registry/auth cd ~/docker-registry/auth ```
```bash htpasswd -Bc registry.password username ```
You will be prompted to set a password for the user.
```bash nano ~/docker-registry/docker-compose.yml ```
```yaml environment: REGISTRY_AUTH: htpasswd REGISTRY_AUTH_HTPASSWD_REALM: Registry REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password ```
Save and close the file.
```bash docker-compose up -d ```
Your registry is now secured with basic authentication.
```bash nano ~/docker-registry/docker-compose.yml ```
```yaml restart: always ```
Save and close the file.
```bash docker-compose up -d ```
Your Docker Registry will now start automatically on system boot and recover from crashes.
```bash sudo nano /etc/nginx/nginx.conf ```
```nginx client_max_body_size 16384m; ```
Save and close the file.
```bash sudo systemctl restart nginx ```
Nginx is now configured to accept larger file uploads.
```bash docker login https://your_domain ```
```bash docker tag test-image your_domain/test-image ```
```bash docker push your_domain/test-image ```
Your image is now securely stored in your private Docker Registry.
```bash docker login https://your_domain ```
```bash docker pull your_domain/test-image ```
```bash docker run -it your_domain/test-image ```
This revised tutorial removes specific website links and focuses on the essential steps to set up a private Docker Registry on Ubuntu 22.04. You should replace placeholders like `your_domain` and customize it according to your needs.
Have additional questions? Search below: