Skip to content

Instantly share code, notes, and snippets.

@danbev
Last active February 17, 2016 15:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danbev/497d9368a98b04563296 to your computer and use it in GitHub Desktop.
Save danbev/497d9368a98b04563296 to your computer and use it in GitHub Desktop.
Import Docker image

Say that you have followed the instructions in import.md and now want to update a deployment configuration or a running pod so that it uses that image.

First list the image of intrest:

$ docker images
REPOSITORY                                                    TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
danbev/es                                                     latest              59d06a20aff1        17 hours ago        415.9 MB

First tag the image. Add the namespace/project name after the registry ip:port. For example, I'm going to add the image to the mbaas-logging namespace/project

$ docker tag 59d06a20aff1 172.30.198.116:5000/mbaas-logging/danbev-es
$ docker images
REPOSITORY                                                    TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
172.30.198.116:5000/mbaas-logging/danbev-es                                 latest              59d06a20aff1        17 hours ago        415.9 MB
danbev/es                                                     latest              59d06a20aff1        17 hours ago        415.9 MB

Now, push the tagged image into the private repository:

$ docker push 172.30.198.116:5000/mbaas-logging/danbev-es
The push refers to a repository [172.30.198.116:5000/mbaas-logging/danbev-es] (len: 1)
59d06a20aff1: Preparing
Post http://172.30.198.116:5000/v2/danbev/es/blobs/uploads/: no basic auth credentials

So, that failed. How do we set up the correct credentials? The issue is that I've already logged in to docker.io. I need to login to 172.30.198.116:5000 I think. To get a token for the login I did:

$ oc login -u test -p test
$ $ oc whoami -t

Now, copy the token from the response above and use it in the following command:

$ docker login -u test -p token -e dbevenius@redhat.com 172.30.198.116:5000
WARNING: login credentials saved in /home/vagrant/.docker/config.json
Login Succeeded

But we are not done yet. Simply trying to push the image again will fail with the following error message:

The push refers to a repository [172.30.198.116:5000/mbaas-logging/danbev-es] (len: 1)
59d06a20aff1: Preparing
unauthorized: access to the requested resource is not authorized

We have to give the user test the correct permissions.

$ oc login --username=system:admin
$ oadm policy add-role-to-user system:registry test
$ oadm policy add-role-to-user admin test -n mbaas-logging
$ oadm policy add-role-to-user system:image-builder test

Now, lets try pushing again:

$ docker push 172.30.198.116:5000/mbaas-logging/danbev-es:latest
The push refers to a repository [172.30.198.116:5000/mbaas-logging/danbev-es] (len: 1)
59d06a20aff1: Pushed
e3dd683dc684: Pushed
26b2d6e283c9: Pushed
f33fed2c596b: Pushed
ec7f56a8b7ce: Pushed
deaac687339f: Pushed
19f9a5ae3587: Pushed
3454f42095bb: Pushed
f00d0f39e6db: Pushed
8581d1e530b3: Pushed
47a93cbdf944: Pushed
73dd0c4c7c79: Pushed
f2f20b4e1e6b: Pushed
60e65a8e4030: Image already exists
5764f0a31317: Image already exists
838c1c5c4f83: Pushed
47d44cb6f252: Image already exists
latest: digest: sha256:c8eb64da741e61e18dd39c01c3026d23bd25dd9b215fd9ab72db3106c8a45987 size: 44337

Success, that was simple ;)

Shows an example of building a DockerImage in one docker and importing it into another.

Exporting

For this example I'm using this DockerFile

$ docker build -t danbev/es .
$ docker save danbev/es > danbev-es.tar

Loading into Docker

$ docker load < danbev-es.tar

The image is now availalbe in Docker.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment