Docker: добавить свой образ в репозиторий на Docker Hub

Автор: | 15/07/2016
 

docker_lxcОфициальный docker-образ от Microsoft содержал Azure CLI версии 0.9.8, а требовалась 0.10.

Пример сборки и отправки в Docker Hub образа с azure-cli 0.10.2.

Содержимое Dockerfile:

FROM ubuntu:14.04
RUN apt-get update && apt-get install -y \
    node.js npm \
    && ln -s /usr/bin/nodejs /usr/bin/node \
    && npm install azure-cli -g

Собираем:

$ sudo docker build -t setevoy/azure-cli .
Sending build context to Docker daemon 1.469 GB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:14.04
14.04: Pulling from ubuntu

b28db778d4f7: Pull complete 
2334d959c0cf: Pull complete 
20fc819717cc: Pull complete 
62059538b3f4: Pull complete 
f8bd1e6f7e58: Pull complete 
Digest: sha256:721b91d5bd46c1ec7130f40fa9f05cdfe73cf50be82056c2046cd0a2cb3f1d8a
Status: Downloaded newer image for ubuntu:14.04
 ---> f8bd1e6f7e58
Step 1 : RUN apt-get update && apt-get install -y     node.js npm     && ln -s /usr/bin/nodejs /usr/bin/node     && npm install azure-cli -g
 ---> Running in 354f9db7c1ef
Ign http://archive.ubuntu.com trusty InRelease
Get:1 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:2 http://archive.ubuntu.com trusty-security InRelease [65.9 kB]
Get:3 http://archive.ubuntu.com trusty Release.gpg [933 B]
...
└── [email protected] ([email protected], [email protected], [email protected])
 ---> 47058f28a32c
Removing intermediate container 354f9db7c1ef
Successfully built 47058f28a32c

Проверяем его наличие:

$ sudo docker images | grep azure
setevoy/azure-cli latest 47058f28a32c About a minute ago 532.7 MB
microsoft/azure-cli latest 27e1046b4479 5 days ago 531.2 MB

Логинимся в Docker Hub:

$ sudo docker login
Username: setevoy
Password:
Email: user@setevoy.kiev.ua
WARNING: login credentials saved in /home/setevoy/.dockercfg.
Login Succeeded

Можно поискать аналогичные образы:

$ sudo docker search azure-cli
NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
microsoft/azure-cli                  Docker image for Microsoft Azure Command L...   56                   [OK]
activatedgeek/azure-cli              Azure CLI inside Alpine Docker                  1                    [OK]
hbai/azurecli                        use Docker and Azure CLI to deliver a smoo...   1                    
generik/azure-cli                    Azure CLI Tools from Microsoft in a 3x sma...   1                    [OK]
sequenceiq/azure-cli-tools           Command line tool to deploy the MicrosoftD...   1                    [OK]
...

И добавить свой:

$ sudo docker push setevoy/azure-cli
The push refers to a repository [setevoy/azure-cli] (len: 1)
47058f28a32c: Image already exists 
f8bd1e6f7e58: Image successfully pushed 
62059538b3f4: Image successfully pushed 
20fc819717cc: Image successfully pushed 
2334d959c0cf: Image successfully pushed 
b28db778d4f7: Image successfully pushed 
Digest: sha256:2cc1dc3deb74f9e27d87a3361803335d16478e8658c8b0e3f2e1105fd4764930

Если после Ctrl+C будет ошибка вида:

FATA[0000] Error response from daemon: push setevoy/azure-cli is already in progress

Перезапустите Docker (правда потом вероятна ошибка “Image already exists“):

$ sudo service docker restart
docker stop/waiting
docker start/running, process 12074

Проверяем:

$ sudo docker search azure-cli | grep setevoy
setevoy/azure-cli                    Azure-CLI (Node), Ubuntu 14.04                  0

И запускаем:

$ sudo docker run -ti setevoy/azure-cli
root@e5a5a8f1304d:/# azure --version
0.10.2 (node: 0.10.25)

Готово.