How to migrate an image from docker to a private registry

Source: Internet
Author: User

Docker is getting more and more popular. If your team is ready to start using docker, private warehouses are essential. First, they can help you speed up pull images from servers, this document describes how to back up open images from a public server to a local private server.

This document uses the ubuntu image in index as an example.

Download the ubuntu image from the official Index Server
docker pull ubuntu
View existing images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Ubuntu 13.10 9f676bd305a4 5 weeks ago 178 MB
Ubuntu Saucy 9f676bd305a4 5 weeks ago 178 MB
Ubuntu Raring Eb601b8965b8 5 weeks ago 166.5 MB
Ubuntu 13.04 Eb601b8965b8 5 weeks ago 166.5 MB
Ubuntu 12.10 5ac751e8d623 5 weeks ago 161 MB
Ubuntu Quantal 5ac751e8d623 5 weeks ago 161 MB
Ubuntu 10.04 9cc9ea5ea540 5 weeks ago 180.8 MB
Ubuntu Lucid 9cc9ea5ea540 5 weeks ago 180.8 MB
Ubuntu 12.04 9cd978db300e 5 weeks ago 204.4 MB
Ubuntu Latest 9cd978db300e 5 weeks ago 204.4 MB
Ubuntu Precise 9cd978db300e 5 weeks ago 204.4 MB

Generally, we will use the latest ubuntu version. You can find that multiple tags correspond to the same image, and the TAG is just a name.

Tag the image to be pushed to the private registry.
docker tag 9cd978db300e rd-server:5000/ubuntu

We can run docker images to check the effect.

REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
Ubuntu 13.10 9f676bd305a4 5 weeks ago 178 MB
Ubuntu Saucy 9f676bd305a4 5 weeks ago 178 MB
Ubuntu Raring Eb601b8965b8 5 weeks ago 166.5 MB
Ubuntu 13.04 Eb601b8965b8 5 weeks ago 166.5 MB
Ubuntu 12.10 5ac751e8d623 5 weeks ago 161 MB
Ubuntu Quantal 5ac751e8d623 5 weeks ago 161 MB
Ubuntu 10.04 9cc9ea5ea540 5 weeks ago 180.8 MB
Ubuntu Lucid 9cc9ea5ea540 5 weeks ago 180.8 MB
Ubuntu 12.04 9cd978db300e 5 weeks ago 204.4 MB
Ubuntu Latest 9cd978db300e 5 weeks ago 204.4 MB
Ubuntu Precise 9cd978db300e 5 weeks ago 204.4 MB
Rd-server: 5000/ubuntu Latest 9cd978db300e 5 weeks ago 204.4 MB
Push ubuntu to private registry
docker push rd-server:5000/ubuntu
How can I mirror all the branches of ubuntu to my own private repository?

1. TAG the required version and push it.

The statement looks like this:

docker tag eb601b8965b8 rd-server:5000/ubuntu:raringdocker tag eb601b8965b8 rd-server:5000/ubuntu:13.04docker tag 9f676bd305a4 rd-server:5000/ubuntu:saucydocker tag 9f676bd305a4 rd-server:5000/ubuntu:13.10docker tag 9cd978db300e rd-server:5000/ubuntu:precisedocker tag 9cd978db300e rd-server:5000/ubuntu:latestdocker tag 9cd978db300e rd-server:5000/ubuntu:12.04docker tag 9cc9ea5ea540 rd-server:5000/ubuntu:luciddocker tag 9cc9ea5ea540 rd-server:5000/ubuntu:10.04docker tag 5ac751e8d623 rd-server:5000/ubuntu:quantaldocker tag 5ac751e8d623 rd-server:5000/ubuntu:12.10

Start push

docker push rd-server:5000/ubuntu

If the last row of the returned content is as follows:

2014/03/14 08:22:14 push: }

Please execute it repeatedly. No doubt. Please execute it repeatedly.

docker pull rd-server:5000/ubuntu

Until the words "push:}" are no longer displayed.

I don't know whether this is a docker BUG or the design is like this. I need to push the complete tag to the private registry multiple times, otherwise, the client will always prompt that some images cannot be found during download. I guess this may be the case because the docker image is large and a repo will have a lot of block files, only one block is pushed each time. Well, I guess this is the case and I still have to work. So, write a script to solve the manual problem.

#!/bin/sh##Copyright (c) 2014 ZhengXujin xujinzheng@gmail.com#server="127.0.0.1:5000"index_repo_name="username/ubuntu"private_repo_name="ubuntu"echo "\n"echo "                        ##        ."echo "                  ## ## ##       =="echo "               ## ## ## ##      ==="echo "           /""""""""""""""""\___/ ==="echo "      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~"echo "           \______ o          __/"echo "             \    \        __/"echo "              \____\______/" echo "\n"idx=0is_continue=1docker images|grep -q "$server/$private_repo_name"if [[ $? -ne 0 ]]; then    docker images|grep $index_repo_name|awk -F" " '{printf("docker tag %s %s/%s:%s\n",$3,"'$server'","'$private_repo_name'",$2)}'|bashfiwhile [ $is_continue -eq 1 ]do   docker push $server/$private_repo_name   is_continue=$?   let idx=$idx+1   echo "$(tput setaf 1)continue push, $idx times pushed. $(tput sgr 0)"done
Obtain the image of the private library from the client
docker pull rd-server:5000/ubuntu

Or you can obtain ubuntu of a specific version.

docker pull -t 13.04 rd-server:5000/ubuntu

When pushing data from a public database to a private database, some dependent images may not be completely pushed to the server. An error may occur when pull is on the client. The prompt is as follows:

eb601b8965b8: Error pulling image (13.04) from rd-server:5000/ubuntu, Server error: 400 trying to fetch remote history for eb601b9cd978db300e: Download complete

Execute the following statement repeatedly until all images are uploaded.

docker push rd-server:5000/ubuntu

Of course, not every time this problem occurs, it is caused by incomplete upload. It may also be because the pull client network is poor. If the same problem occurs repeatedly, you need to consider the above method.

If the following problem occurs, replace the host name with an IP address for the pull database.

Invalid Registry endpoint: Get http://rd-server:5000/v1/_ping: dial tcp: lookup rd-server: no such host

For example

docker pull 172.16.1.88:5000/ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.