Docker Image Sharing - Export Import

From CompleteNoobs
Jump to navigation Jump to search
Please Select a Licence from the LICENCE_HEADERS page
And place at top of your page
If no Licence is Selected/Appended, Default will be CC0

Default Licence IF there is no Licence placed below this notice! When you edit this page, you agree to release your contribution under the CC0 Licence

LICENCE: More information about the cc0 licence can be found here:
https://creativecommons.org/share-your-work/public-domain/cc0

The person who associated a work with this deed has dedicated the work to the public domain by waiving all of his or her rights to the work worldwide under copyright law, including all related and neighboring rights, to the extent allowed by law.

You can copy, modify, distribute and perform the work, even for commercial purposes, all without asking permission.

Licence:

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer exclusive Copyright and Related Rights (defined below) upon the creator and subsequent owner(s) (each and all, an "owner") of an original work of authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for the purpose of contributing to a commons of creative, cultural and scientific works ("Commons") that the public can reliably and without fear of later claims of infringement build upon, modify, incorporate in other works, reuse and redistribute as freely as possible in any form whatsoever and for any purposes, including without limitation commercial purposes. These owners may contribute to the Commons to promote the ideal of a free culture and the further production of creative, cultural and scientific works, or to gain reputation or greater distribution for their Work in part through the use and efforts of others.

For these and/or other purposes and motivations, and without any expectation of additional consideration or compensation, the person associating CC0 with a Work (the "Affirmer"), to the extent that he or she is an owner of Copyright and Related Rights in the Work, voluntarily elects to apply CC0 to the Work and publicly distribute the Work under its terms, with knowledge of his or her Copyright and Related Rights in the Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be protected by copyright and related or neighboring rights ("Copyright and Related Rights"). Copyright and Related Rights include, but are not limited to, the following:

   the right to reproduce, adapt, distribute, perform, display, communicate, and translate a Work;
   moral rights retained by the original author(s) and/or performer(s);
   publicity and privacy rights pertaining to a person's image or likeness depicted in a Work;
   rights protecting against unfair competition in regards to a Work, subject to the limitations in paragraph 4(a), below;
   rights protecting the extraction, dissemination, use and reuse of data in a Work;
   database rights (such as those arising under Directive 96/9/EC of the European Parliament and of the Council of 11 March 1996 on the legal protection of databases, and under any national implementation thereof, including any amended or successor version of such directive); and
   other similar, equivalent or corresponding rights throughout the world based on applicable law or treaty, and any national implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention of, applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and unconditionally waives, abandons, and surrenders all of Affirmer's Copyright and Related Rights and associated claims and causes of action, whether now known or unknown (including existing as well as future claims and causes of action), in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each member of the public at large and to the detriment of Affirmer's heirs and successors, fully intending that such Waiver shall not be subject to revocation, rescission, cancellation, termination, or any other legal or equitable action to disrupt the quiet enjoyment of the Work by the public as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason be judged legally invalid or ineffective under applicable law, then the Waiver shall be preserved to the maximum extent permitted taking into account Affirmer's express Statement of Purpose. In addition, to the extent the Waiver is so judged Affirmer hereby grants to each affected person a royalty-free, non transferable, non sublicensable, non exclusive, irrevocable and unconditional license to exercise Affirmer's Copyright and Related Rights in the Work (i) in all territories worldwide, (ii) for the maximum duration provided by applicable law or treaty (including future time extensions), (iii) in any current or future medium and for any number of copies, and (iv) for any purpose whatsoever, including without limitation commercial, advertising or promotional purposes (the "License"). The License shall be deemed effective as of the date CC0 was applied by Affirmer to the Work. Should any part of the License for any reason be judged legally invalid or ineffective under applicable law, such partial invalidity or ineffectiveness shall not invalidate the remainder of the License, and in such case Affirmer hereby affirms that he or she will not (i) exercise any of his or her remaining Copyright and Related Rights in the Work or (ii) assert any associated claims and causes of action with respect to the Work, in either case contrary to Affirmer's express Statement of Purpose.

4. Limitations and Disclaimers.

   No trademark or patent rights held by Affirmer are waived, abandoned, surrendered, licensed or otherwise affected by this document.
   Affirmer offers the Work as-is and makes no representations or warranties of any kind concerning the Work, express, implied, statutory or otherwise, including without limitation warranties of title, merchantability, fitness for a particular purpose, non infringement, or the absence of latent or other defects, accuracy, or the present or absence of errors, whether or not discoverable, all to the greatest extent permissible under applicable law.
   Affirmer disclaims responsibility for clearing rights of other persons that may apply to the Work or any use thereof, including without limitation any person's Copyright and Related Rights in the Work. Further, Affirmer disclaims responsibility for obtaining any necessary consents, permissions or other rights required for any use of the Work.
   Affirmer understands and acknowledges that Creative Commons is not a party to this document and has no duty or obligation with respect to this CC0 or use of the Work.

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

  1. Open your web browser
  2. Navigate to: https://hub.docker.com
  3. Click Sign Up button (top right)
  4. 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)
  5. Complete the CAPTCHA
  6. Click Sign Up
  7. 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

  1. Return to https://hub.docker.com
  2. Click Sign In
  3. Enter your Docker ID and password
  4. You'll see your Docker Hub dashboard

Step 2: Create Repository on Docker Hub

2.1: Create New Repository

  1. On Docker Hub dashboard, click Create Repository
  2. Fill in repository details:
    • Name: wiki (or completenoobs-wiki)
    • Description: CompleteNoobs Wiki - MediaWiki with pre-imported content from CompleteNoobs.com
    • Visibility: Select Public (free) or Private (requires subscription)
  3. 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

  1. Go to: https://hub.docker.com/r/yourdockerid/wiki
  2. You should see:
    • Your repository
    • Tags (latest, 1.0)
    • Last pushed timestamp
    • Image size
    • Pull count (starts at 0)

6.2: Update Repository Description

  1. Click on your repository
  2. Click Manage Repository (gear icon)
  3. Add a detailed description
  4. 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

Step 8: Share With Others

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):

  1. Copy the .tar file to the external drive:
cp /path/to/backup/my-image.tar /mnt/external/
  1. Verify the file on the external drive:
ls /mnt/external/
  1. 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