Docker Image Sharing - Export Import: Difference between revisions
Created page with "= Upload Your Docker Image to Docker Hub on Ubuntu 24.04 - Complete Beginner's Guide = This tutorial will walk you through uploading your first Docker image to Docker Hub, making it available for anyone to download and run. We'll use the CompleteNoobs Wiki image as our example. == What is Docker Hub? == Docker Hub is like GitHub but for Docker images. It's a cloud-based registry where you can: * Store your Docker images publicly (free) or privately (paid) * Share conta..." |
(No difference)
|
Latest revision as of 17:41, 1 September 2025
Upload Your Docker Image to Docker Hub on Ubuntu 24.04 - Complete Beginner's Guide
This tutorial will walk you through uploading your first Docker image to Docker Hub, making it available for anyone to download and run. We'll use the CompleteNoobs Wiki image as our example.
What is Docker Hub?
Docker Hub is like GitHub but for Docker images. It's a cloud-based registry where you can:
- Store your Docker images publicly (free) or privately (paid)
- Share containers with the community
- Download images others have created
- Automate builds from GitHub repositories
Prerequisites
- Ubuntu 24.04 with Docker installed
- A working Docker image (we'll use completenoobs/wiki:latest from the previous tutorial)
- Internet connection
- Email address for Docker Hub account
Step 1: Create Docker Hub Account
1.1: Sign Up
- Open your web browser
- Navigate to: https://hub.docker.com
- Click Sign Up button (top right)
- Fill in the registration form:
- Docker ID: Choose a unique username (e.g., "yourname" or "completenoobs")
- Email: Your email address
- Password: Strong password (mix of letters, numbers, symbols)
- Complete the CAPTCHA
- Click Sign Up
- Verify your email (check inbox for Docker confirmation email)
Important: Your Docker ID becomes part of your image name (e.g., yourname/wiki:latest)
1.2: Sign In to Docker Hub
- Return to https://hub.docker.com
- Click Sign In
- Enter your Docker ID and password
- You'll see your Docker Hub dashboard
Step 2: Create Repository on Docker Hub
2.1: Create New Repository
- On Docker Hub dashboard, click Create Repository
- Fill in repository details:
- Name:
wiki
(orcompletenoobs-wiki
) - Description:
CompleteNoobs Wiki - MediaWiki with pre-imported content from CompleteNoobs.com
- Visibility: Select Public (free) or Private (requires subscription)
- Name:
- Click Create
You now have a repository at: docker.io/yourdockerid/wiki
Step 3: Login to Docker Hub from Terminal
3.1: Open Terminal
# Open terminal on Ubuntu 24.04
# You can use Ctrl+Alt+T or search for "Terminal"
3.2: Login to Docker Hub
docker login
You will see:
USING WEB-BASED LOGIN
i Info → To sign in with credentials on the command line, use 'docker login -u <username>'
Your one-time device confirmation code is: MPMR-BKUH
Press ENTER to open your browser or submit your device code here: https://login.docker.com/activate
Waiting for authentication in the browser…
go to https://login.docker.com/activate and enter the confirmation code, after which you will be asked to sign into docker, after that your set.
the terminal will change to include:
WARNING! Your credentials are stored unencrypted in '/home/noob/.docker/config.json'. Configure a credential helper to remove this warning. See https://docs.docker.com/go/credential-store/ Login Succeeded
Step 4: Prepare Your Image
4.1: Check Your Local Images
docker images
You should see:
REPOSITORY TAG IMAGE ID CREATED SIZE
completenoobs/wiki latest abc123def456 2 hours ago 1.5GB
4.2: Tag Your Image for Docker Hub
Replace wiki
with your repo name
Replace yourdockerid
with your actual Docker ID:
- Syntax:
docker tag YOURDOCKERID/YOUR_REPO_NAME:VERSION
# Tag your image with your Docker Hub username
docker tag completenoobs/wiki:latest yourdockerid/wiki:latest
# Also create a version tag for better practice
docker tag completenoobs/wiki:latest yourdockerid/wiki:1.0
# Verify the tags
docker images
docker images | grep wiki
You should now see multiple tags for the same image ID.
Step 5: Push Image to Docker Hub
5.1: Push the Image
# Push the latest tag
docker push yourdockerid/wiki:latest
# Push the version tag
docker push yourdockerid/wiki:1.0
You'll see upload progress:
The push refers to repository [docker.io/yourdockerid/wiki]
a1b2c3d4e5f6: Pushing [==============> ] 45.3MB/150MB
7g8h9i0j1k2l: Pushed
3m4n5o6p7q8r: Pushing [========> ] 25.6MB/100MB
...
latest: digest: sha256:abc123... size: 3245
Note: First push takes longer (uploads all layers). Subsequent pushes only upload changes.
Step 6: Verify Upload
6.1: Check on Docker Hub
- Go to: https://hub.docker.com/r/yourdockerid/wiki
- You should see:
- Your repository
- Tags (latest, 1.0)
- Last pushed timestamp
- Image size
- Pull count (starts at 0)
6.2: Update Repository Description
- Click on your repository
- Click Manage Repository (gear icon)
- Add a detailed description
- Add README content (supports Markdown):
CompleteNoobs Wiki Docker Image
Pre-configured MediaWiki with CompleteNoobs.com content - For Local Use.
May require an update after first install - as for some reason some pages missing from first xml import
```bash
docker exec -it completenoobs_wiki /var/www/html/check_updates.sh
```
## Quick Start
```bash
docker run -d -p 8080:80 yourdockerid/wiki:latest
```
##Quick Start with Persistent Storage
```bash
docker run -d -p 8080:80 \
-v completenoobs_mysql:/var/lib/mysql \
-v completenoobs_images:/var/www/html/images \
--name completenoobs_wiki \
completenoobs/cnoobs-wiki:latest
```
## Features
- MediaWiki 1.44
- Pre-imported CompleteNoobs content
- YouTube extension
- PageNotice extension
- SyntaxHighlight support
- XML update system
## Default Credentials
- Username: admin
- Password: AdminPass123!
## Volumes
- `/var/lib/mysql` - Database storage
- `/var/www/html/images` - Uploaded images
## More Information
Visit: https://completenoobs.com
Step 7: Test Download (Verify It Works)
7.1: Remove Local Images (Optional)
To truly test downloading from Docker Hub:
# Stop and remove container if running
docker stop completenoobs_wiki
docker rm completenoobs_wiki
# Remove local images
docker rmi yourdockerid/wiki:latest
docker rmi yourdockerid/wiki:1.0
docker rmi completenoobs/wiki:latest
7.2: Pull From Docker Hub
# Pull your image from Docker Hub
docker pull yourdockerid/wiki:latest
# Run it
docker run -d -p 8080:80 --name test_wiki yourdockerid/wiki:latest
# Check it's working
docker logs test_wiki
curl http://localhost:8080
8.1: Basic Run Command
Share this simple command for others to use your image:
docker run -d -p 8080:80 yourdockerid/wiki:latest
8.2: Docker Compose File
Create a docker-compose.yml
for easier deployment:
- With version 0.1 its all in one container so these commands do not really apply - just placeholder do now - will fix for 0.2
version: '3.8'
services:
wiki:
image: yourdockerid/wiki:latest
container_name: completenoobs_wiki
ports:
- "8080:80"
volumes:
- mysql_data:/var/lib/mysql
- wiki_images:/var/www/html/images
restart: unless-stopped
environment:
- TZ=America/New_York # Adjust timezone
volumes:
mysql_data:
wiki_images:
Step 9: Best Practices
9.1: Versioning
Always use version tags alongside 'latest':
# Bad (only latest)
docker push yourdockerid/wiki:latest
# Good (version + latest)
docker push yourdockerid/wiki:1.0
docker push yourdockerid/wiki:latest
# When updating
docker tag yourdockerid/wiki:latest yourdockerid/wiki:1.1
docker push yourdockerid/wiki:1.1
docker push yourdockerid/wiki:latest
9.2: Image Size Optimization
Before pushing, consider reducing image size:
# Check image size
docker images yourdockerid/wiki
# Remove unnecessary files in Dockerfile
# Use multi-stage builds if possible
# Clean package manager cache
9.3: Security
- Never include passwords in image (use environment variables)
- Regularly update base images
- Scan for vulnerabilities:
# Docker Scout (built-in to Docker Desktop)
docker scout cves yourdockerid/wiki:latest
# Or use Trivy
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock \
aquasec/trivy image yourdockerid/wiki:latest
Step 10: Maintain Your Image
10.1: Update Your Image
When you need to update:
# 1. Make changes to Dockerfile or scripts
cd ~/completenoobs-docker-image
# 2. Rebuild with new version
docker build -t yourdockerid/wiki:1.1 .
# 3. Test locally
docker run -d -p 8080:80 --name test yourdockerid/wiki:1.1
# ... test everything works ...
docker stop test && docker rm test
# 4. Tag as latest
docker tag yourdockerid/wiki:1.1 yourdockerid/wiki:latest
# 5. Push both tags
docker push yourdockerid/wiki:1.1
docker push yourdockerid/wiki:latest
# 6. Update Docker Hub description with changelog
10.2: Monitor Usage
Check Docker Hub regularly for:
- Pull count (how many times downloaded)
- User issues (check if you've linked a GitHub repo)
- Security scanning results
Backup Docker Image Locally
To back up a Docker image locally as a .tar file, which can then be stored on an external drive or transferred to another server, follow these steps.
Steps
Save the Docker Image to a .tar File
Use the docker save
command to export the image to a tarball:
docker save -o /path/to/backup/my-image.tar my-image:latest
-o
: Specifies the output file path (e.g.,/path/to/backup/my-image.tar
).my-image:latest
: The name and tag of the image to back up.
Example:
docker save -o /home/user/backups/my-image.tar my-image:latest
Verify the Tarball
Ensure the .tar file was created:
ls -lh /path/to/backup/my-image.tar
Store on an External Drive
To store the image on an external drive (e.g., mounted at /mnt/external
):
- Copy the .tar file to the external drive:
cp /path/to/backup/my-image.tar /mnt/external/
- Verify the file on the external drive:
ls /mnt/external/
- Safely unmount the external drive after copying:
sudo umount /mnt/external
Send Docker Image to Another Server
To transfer the saved Docker image to another server, use tools like scp
, rsync
, or sftp
to securely copy the .tar file.
Steps
Save the Docker Image
Follow the same docker save
step as above to create the .tar file:
docker save -o /path/to/backup/my-image.tar my-image:latest
Transfer the Image to Another Server
Use scp
to copy the .tar file to the remote server:
scp /path/to/backup/my-image.tar user@remote-server:/path/to/destination/
- Replace
user
with the remote server's username. - Replace
remote-server
with the server's IP address or hostname. - Replace
/path/to/destination/
with the destination path on the remote server.
Example:
scp /home/user/backups/my-image.tar admin@192.168.1.100:/home/admin/backups/
Load the Image on the Remote Server
On the remote server, use docker load
to import the .tar file into Docker:
docker load -i /path/to/destination/my-image.tar
Example:
docker load -i /home/admin/backups/my-image.tar
Verify the image is loaded:
docker images
Additional Tips
Compress the Image (Optional)
To save space, compress the .tar file before storing or transferring:
gzip /path/to/backup/my-image.tar
This creates my-image.tar.gz
. To decompress on the destination:
gunzip /path/to/backup/my-image.tar.gz
Use rsync for Large Files
For large .tar files, rsync
can be more reliable than scp
:
rsync -avz /path/to/backup/my-image.tar user@remote-server:/path/to/destination/
Automate Backups
Create a script (e.g., backup_docker.sh
) to automate backups:
#!/bin/bash IMAGE_NAME="my-image:latest" BACKUP_PATH="/home/user/backups" TIMESTAMP=$(date +%F_%H-%M-%S) docker save -o "$BACKUP_PATH/my-image-$TIMESTAMP.tar" $IMAGE_NAME
Make it executable:
chmod +x backup_docker.sh
Schedule it with cron:
crontab -e
Add a line to run daily at midnight:
0 0 * * * /path/to/backup_docker.sh
Check Disk Space
Before saving or copying, ensure there's enough disk space:
df -h /path/to/backup df -h /mnt/external
Restoring the Image Locally
To restore the image from an external drive or a local .tar file:
docker load -i /path/to/backup/my-image.tar
Verify:
docker images
Common Issues and Solutions
Issue: "denied: requested access to the resource is denied"
Solution: You're not logged in or using wrong username
docker logout
docker login
# Make sure to use YOUR Docker ID in the tag
docker tag completenoobs/wiki:latest YOURDOCKERID/wiki:latest
Issue: "name unknown: repository name must be lowercase"
Solution: Docker Hub requires lowercase names
# Wrong
docker tag image:latest YourName/Wiki:latest
# Correct
docker tag image:latest yourname/wiki:latest
Issue: Push takes forever
Solution: Large images take time on first push
- Be patient (can take 30+ minutes for large images)
- Ensure stable internet connection
- Consider optimizing image size
- Use
.dockerignore
file to exclude unnecessary files
Issue: "filesystem layer verification failed"
Solution: Corrupted layer, rebuild and repush
docker build --no-cache -t yourdockerid/wiki:latest .
docker push yourdockerid/wiki:latest
Issue: Error response from daemon: Get "https://registry-1.docker.io/v2/completenoobs/cnoobs-wiki/manifests/sha256:d6cc": net/http: TLS handshake timeout
If then pulling a container docker pull completenoobs/cnoobs-wiki:0.1
you see this error:
Error response from daemon: Get "https://registry-1.docker.io/v2/completenoobs/cnoobs-wiki/manifests/sha256:d6cc65ee8f9716986c6b406a9c037b18ab3cf39326b21b42c6ad0d84c80693f4": net/http: TLS handshake timeout
- Then restart docker
sudo systemctl restart docker
Example Commands Summary
For quick reference, here are all the essential commands:
# Login to Docker Hub
docker login
# Tag your image
docker tag completenoobs/wiki:latest yourdockerid/wiki:latest
docker tag completenoobs/wiki:latest yourdockerid/wiki:1.0
# Push to Docker Hub
docker push yourdockerid/wiki:latest
docker push yourdockerid/wiki:1.0
# Others can now pull and run
docker pull yourdockerid/wiki:latest
docker run -d -p 8080:80 yourdockerid/wiki:latest
# Logout when done
docker logout