Creating the docker
If you are new to docker, I would recommend this article for some basics docker commands and how to create your
Dockerfile, docker images and running container.
I will first create a simple dockerfile with python 3.6
and pytest
in order to have a ready docker to run some tests.
FROM python:3.6.6
RUN pip install pytest pytest-cov
Building my docker image using:
docker build . -t python3-pytest
I tagged the built image to python3-pytest
, so it doesn’t have a random name.
Then I can make sure it works as intended using:
docker run -t python3-pytest python -m pytest
Uploading to the registry
The default docker push would upload the image on hub.docker.com, but it’s a private image, so I want to upload it in my private artifactory registry at artifactory.private.registry.ca:5000.
Artifactory made by JFrog is a solution for hosting, managing, and distributing binaries and artifacts. Including docker images. But this procedure could work with any other registry type as the docker commands are agnostics.
Step by step
Let’s prepare the docker image using this command to push docker image to the private registry. First we tag the image using the registry host (see the docker command parameters in comment).
# docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
docker tag python3-pytest artifactory.private.registry.ca:5000/python/python3-pytest:1
Before the upload, I need to log in using:
docker login artifactory.private.registry.ca:5000
Then I just need to push it and it’s done:
docker push artifactory.private.registry.ca:5000/python/python3-pytest:1
Using a docker from that registry
Now that you have uploaded your image, you can delete the local one to try and pull it from artifactory with the correct tag using the following command:
docker pull artifactory.private.registry.ca:5000/python/python3-pytest:1
# Run the docker with the -t to allocate a pseudo-TTY
docker run -t artifactory.private.registry.ca:5000/python/python3-pytest:1
And that’s it! You may find the uploaded image on artifactory via the UI using the image name in the URL path like: artifactory.private.registry.ca:5000/ui/repos/tree/General/docker-local/python/python3-pytest. It could change depending on your version and installation of artifactory.