Red Hat Openshift Docker Image management notes

Working with image registries

Before you can work with images, you need to have a registry to put the images you create. These commands and setups are done on Fedora 29. Most commands will with Linux. First thing, install Docker.
You can find the instructions for docker-ce here or on the Docker website You can also find other installation instruction for Ubuntu, Windows, and Debian.

Setup local docker registry

Now that you have docker installed, you can setup a local registry. A registry is nothing more than the registry image which runs in Docker.
Docker is already setup to automatically pull from Docker Hub, so you have to have internet connectivity.

To start the registry by executing:

docker run -d -p 5000:5000 --restart always --name registry registry:2

Running ‘docker ps’ and you should see the registry docker running on port 5000. The -p maps the system’s port 5000 to the expose port of the registry 5000. Your local registry will be localhost:5000. In order to use the registry, you rename the image with localhost:5000/<name of image>

docker pull alpine
docker tag alpine localhost:55000/alpine
docker push localhost:5000/apline

You pulled down the alpine latest docker image from Docker Hub. You renamed the image to include your local repository. You pushed the image to your local repository, localhost:5000/alpine. If you want your image to be pushed to your repository, it must be named with your repository and port. If it is a private repository, you would have to login into the repository with docker.
docker login localhost:5000

List images

You can list your current images with

docker images

Load images from archive files

There are times when you want to move an image but cannot do it with docker pull and push. For this you get the image into a tar format. Copy that file where you need it and then load the tar file into an image.

Let’s say you have to move your alpine image to another repository. You are unable to pull or push in your other repository due to some constraint. Pull the image you want down to and change it to a tar file.

docker pull alpine
docker save alpine > alpine.tar

Now transfer that file to where you can Load the file to your other repository. Load the tar file, change the name, and push to your repository

docker load -i alpine.tar
docker tag alpine localhost:5000/alpine
docker push localhost:5000/alpine

Use image tags

Tagging an image is saying what version the image is currently. The default tag is ‘latest’. Examples able show the docker tag command. To change the tag to something else you do

docker tag localhost:5000/alpine localhost:5000/alpine:0.0.1
docker push localhost:5000/alpine:0.0.1

Now if you look in your repository, you will see tags for latest and 0.0.1

docker exec registry ls /var/lib/registry/docker/registry/v2/repositories/alpine/_manifests/tags