Publishing a Docker image to Bintray

StefMa
StefMa
Jul 27, 2017 · 3 min read
Publishing a Docker image to Bintray isn’t that hard — but you have to know how!

Normally I’m a Java guy. So normally you expect a article about Kotlin, gradle or Maven or something. But the fact that all big CI providers backend on Docker lead to the fact that I have to investigate a little bit time into learning Docker.

Let’s start by showing you how to publish a Docker image to Bintray.


1. Create a Docker Repository

First of all, beside of having a Bintray account of course, you have to create a Docker repository on Bintray. Just go to your overview page, click on “Add new Repository”, choose Docker as type, name it somehow (e.g dockerhub) and click create.

2. Credentials

For a successful docker push you have to set up your credentials in a file located at ~/.dockercfg . According to the docs from Bintray you can receive that file via a simple curl command. Unfortunately it wasn’t working for me. I just got the message:

{ 
“message” : ”Repository ‘/<BintrayUsername>/<BintrayRepoName>’ does not support Docker API version v1"
}

That’s the reason why I suggest you to create the file manually.
To file needs the following syntax:

I think the file explained everything what do you have to replace 🙃.

3.1 Publishing — The Docker image

Obviously to publishing a Docker image you need a Docker image first. For testing purpose I’ve created a simple Dockerfile like this:

FROM node:8.2.1

To create the image just run the following command. The <ImageName> can be replaced with any name you like (e.g. bintray-publish-test):

docker build -t <ImageName> .

3.2 Publishing — Tagging

Before you can finally publish the image you have to tag it. Bintray needs a special tag name for it. It’s build in the following way:

<Bintray username>-docker-<Bintray RepoName>.bintray.io/<ImageName>

To take the image you have to first find the image via docker images . This will give you a great overview about all the Docker images on your machine. Find the image you have just created and copy the IMAGE ID .

To tag these image run:

docker tag <ImageId> <TagNameFromAbove👆>

Note: This tag is also your “final” image name. If someone wants to use your image in their Dockerfile they have to use these tag as image name.

3.3 Publishing — Publish 🎉

Now you are finally ready to publish your image. And — it is really simple. Just run

docker push <TagNameFromAbove👆>

4.0 Testing

To verify that everything works correctly you can create a new test project.
For that I created a new Dockerfile with the following content:

FROM <DockerTag>CMD echo “Hello World”

The <DockerTag> is the full name of the tag we have created above 👆.

To make sure that Docker will download the image from Bintray and don’t use a local copy of it remove the images from your machine:

docker rmi <ImageId> -f

Now you can build and run your test Dockerfile :

docker build -t medium-test . 
docker run medium-test

Now you have — hopefully — the Hello World output we expected 🎉.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade