Creating docker image from scratch and adding to local registry

We will create an image from scratch in docker and add that to a docker registry so we can reuse that image when we create new docker instances, controlling the whole flow.

Working with docker and registry

First of we install the docker client, server and registry on our debian machine.

apt install docker docker.io docker-registry

The registry could be installed as a service in our docker cloud as well.

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

Looking at the /etc/docker/registry/config.yml we can add all the configuration we need as well as SSL keys or connections to letencrypt so we can have a free and good connection to our repository. Securing a local or remote repository is key.

Next up we will create our own debian image by bootstrapping the buster distribution.

apt install debootstrap
debootstrap buster buster

Next up we will take that directory, package it up and import that into a new docker image called buster. We also will run it to ensure it works well and have the right version.

tar -C buster -c . | docker import - buster
docker run buster -t container-buster cat /etc/os-release

Next up we tag the newly created version for our repository and then push it up to the repository.

docker tag buster localhost:5000/my-debian
docker push localhost:5000/my-debian

We can now visit the server at http://[ip]:5000/my-debian/tags/list to see that we have a newly uploaded and tagged version in our repository.

Next up we will prune our local system and remove any traces of installed images or containers. This should not be done on a production environment as you may remove running important business logic. But for our example this is fine.

docker system prune -a

Now I will create a simple docker image that will use our debian version and install PHP as a dependency.

from localhost:5000/my-debian

run apt update
run apt install -y php

Building the docker image and then running it to ensure that we have the correct version of PHP is done by the commands below.

docker build -t php-install .
docker run php-install php -v

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.