Private warehouse
Sometimes it may be inconvenient to use a public repository like Docker Hub, and users can create a local repository for private use.
This section describes how to use a local repository.
docker-registry It is an official tool that can be used to build a private mirror repository.
Install and run docker-registry
Container run
After installing Docker, you can run it by getting the official registry image.
$ sudo docker run -d -p 5000:5000 registry
This will use the official registry image to start the local private repository. Users can configure private repository locations by specifying parameters, such as configuring mirrored storage to Amazon S3 services.
$ sudo docker run \ -e SETTINGS_FLAVOR=s3 \ -e AWS_BUCKET=acme-docker \ -e STORAGE_PATH=/registry \ -e AWS_KEY=AKIAHSHB43HS3J92MXZ \ -e AWS_SECRET=xdDowwlK7TJajV1Y7EoOZrmuPEJlHYcNP2k4j49T \ -e SEARCH_BACKEND=sqlalchemy \ -p 5000:5000 \ registry
In addition, you can also specify a local path (e.g. /home/user/registry-conf ) configuration file under .
$ sudo docker run -d -p 5000:5000 -v /home/user/registry-conf:/registry-conf -e DOCKER_REGISTRY_CONFIG=/registry-conf/ registry
By default, the repository is created in the container /tmp/registry Down. The -v parameter can be used to store the image file locally in the specified path. For example, the following example puts the uploaded image into/opt/data/registry Table of contents.
$ sudo docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
Local installation
For distributions such as Ubuntu or CentOS, they can be installed directly from the source.
Ubuntu
$ sudo apt-get install -y build-essential python-dev libevent-dev python-pip liblzma-dev $ sudo pip install docker-registry
CentOS
$ sudo yum install -y python-devel libevent-devel python-pip gcc xz-devel $ sudo python-pip install docker-registry
You can also docker-registry Download the source code for the project to install.
$ sudo apt-get install build-essential python-dev libevent-dev python-pip libssl-dev liblzma-dev libffi-dev $ git clone /docker/ $ cd docker-registry $ sudo python install
Then modify the configuration file, mainly modify the dev template segmentstorage_path The path to the local storage repository.
$ cp config/config_sample.yml config/
Then start the web service.
$ sudo gunicorn -c contrib/ docker_registry.wsgi:application
or
$ sudo gunicorn --access-logfile - --error-logfile - -k gevent -b 0.0.0.0:5000 -w 4 --max-requests 100 docker_registry.wsgi:application
At this time, use curl to access the local port 5000 and see the version information output of docker-registry, which indicates that the run is successful.
Note:The config/config_sample.yml file is a sample configuration file.
Upload, download, search for images in private repository
After creating a private repository, you can use itdocker tag Tag a mirror, then push it to the repository, and you can download it on other machines. For example, the private warehouse address is192.168.7.26:5000。
First check the existing mirror on this machine.
$ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB ubuntu 14.04 ba5877dc9bec 6 weeks ago 192.7 MB
Use docker tag to mark the ba58 image as192.168.7.26:5000/test(Format docker tag IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG])。
$ sudo docker tag ba58 192.168.7.26:5000/test root ~ # docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE ubuntu 14.04 ba5877dc9bec 6 weeks ago 192.7 MB ubuntu latest ba5877dc9bec 6 weeks ago 192.7 MB 192.168.7.26:5000/test latest ba5877dc9bec 6 weeks ago 192.7 MB
Use docker push to upload tagged images.
$ sudo docker push 192.168.7.26:5000/test The push refers to a repository [192.168.7.26:5000/test] (len: 1) Sending image list Pushing repository 192.168.7.26:5000/test (1 tags) Image 511136ea3c5a already pushed, skipping Image 9bad880da3d2 already pushed, skipping Image 25f11f5fb0cb already pushed, skipping Image ebc34468f71d already pushed, skipping Image 2318d26665ef already pushed, skipping Image ba5877dc9bec already pushed, skipping Pushing tag for rev [ba5877dc9bec] on {http://192.168.7.26:5000/v1/repositories/test/tags/latest}
Use curl to view the mirror in the repository.
$ curl http://192.168.7.26:5000/v1/search {"num_results": 7, "query": "", "results": [{"description": "", "name": "library/miaxis_j2ee"}, {"description": "", "name": "library/tomcat"}, {"description": "", "name": "library/ubuntu"}, {"description": "", "name": "library/ubuntu_office"}, {"description": "", "name": "library/desktop_ubu"}, {"description": "", "name": "dockerfile/ubuntu"}, {"description": "", "name": "library/test"}]}
Here you can see {"description": "", "name": "library/test"}, indicating that the image has been successfully uploaded.
Now you can go to another machine to download this image.
$ sudo docker pull 192.168.7.26:5000/test Pulling repository 192.168.7.26:5000/test ba5877dc9bec: Download complete 511136ea3c5a: Download complete 9bad880da3d2: Download complete 25f11f5fb0cb: Download complete ebc34468f71d: Download complete 2318d26665ef: Download complete $ sudo docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 192.168.7.26:5000/test latest ba5877dc9bec 6 weeks ago 192.7 MB
You can use this script to upload local images in batches to the registration server. The default is the local registration server 127.0.0.1:5000. For example:
$ wget /yeasy/docker_practice/raw/master/_local/push_images.sh; sudo chmod a+x push_images.sh $ ./push_images.sh ubuntu:latest centos:centos7 The registry server is 127.0.0.1 Uploading ubuntu:latest... The push refers to a repository [127.0.0.1:5000/ubuntu] (len: 1) Sending image list Pushing repository 127.0.0.1:5000/ubuntu (1 tags) Image 511136ea3c5a already pushed, skipping Image bfb8b5a2ad34 already pushed, skipping Image c1f3bdbd8355 already pushed, skipping Image 897578f527ae already pushed, skipping Image 9387bcc9826e already pushed, skipping Image 809ed259f845 already pushed, skipping Image 96864a7d2df3 already pushed, skipping Pushing tag for rev [96864a7d2df3] on {http://127.0.0.1:5000/v1/repositories/ubuntu/tags/latest} Untagged: 127.0.0.1:5000/ubuntu:latest Done Uploading centos:centos7... The push refers to a repository [127.0.0.1:5000/centos] (len: 1) Sending image list Pushing repository 127.0.0.1:5000/centos (1 tags) Image 511136ea3c5a already pushed, skipping 34e94e67e63a: Image successfully pushed 70214e5d0a90: Image successfully pushed Pushing tag for rev [70214e5d0a90] on {http://127.0.0.1:5000/v1/repositories/centos/tags/centos7} Untagged: 127.0.0.1:5000/centos:centos7 Done
Thank you for reading, I hope it can help you. Thank you for your support for this site!