Preliminary analysis of Docker Registry service start-up process

Source: Internet
Author: User
Tags docker ps docker registry

When we pull a registry image or make a mirror ourselves, using the command Docker run-d-P 5000:5000 Registry, you can start a private container service, so how exactly does it work?

First, Docker PS shows that cmd is "docker-registry", but it is not entered when it is started.
[Email protected]:/home/opuser# Docker PS
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ffca4ca34c3f registry "Docker-registry" , hours ago up, hours 0.0.0.0:5000->5000/tcp desperate_lumiere

Remember that you can specify a command to execute after starting Docker in Dockerfile, and see the Dockerfile to create a registry image
[Email protected]:/# Cat Docker-registry/dockerfile
# VERSION 0.1
# docker-version 0.7.3
# Author:sam Alba <[email protected]>
# Description:image with Docker-registry project and Dependecies
# To_build:docker Build-rm-t registry.
# To_run:docker Run-p 5000:5000 Registry

# Latest Ubuntu LTS
From ubuntu:14.04

# Update
RUN apt-get update \
# Install Pip
&& apt-get install-y \
Swig \
python-pip \
# Install Deps for Backports.lzma (python2 requires it)
python-dev \
python-mysqldb \
python-rsa \
libssl-dev \
liblzma-dev \
libevent1-dev \
# Install Deps for building gevent
Curl \
cython \
&& rm-rf/var/lib/apt/lists/*

COPY. /docker-registry
COPY./config/boto.cfg/etc/boto.cfg

# Install Core
RUN Pip Install/docker-registry/depends/docker-registry-core

# Install Gevent 1.0.1 using updated config.guess and Config.sub
RUN Curl https://pypi.python.org/packages/source/g/gevent/gevent-1.0.1.tar.gz | tar-xzf-c/\
&& Curl-o/gevent-1.0.1/libev/config.guess \
' Http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD ' \
&& Curl-o/gevent-1.0.1/libev/config.sub \
' Http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD ' \
&& cp-pf/gevent-1.0.1/libev/config.guess/gevent-1.0.1/c-ares/config.guess \
&& cp-pf/gevent-1.0.1/libev/config.sub/gevent-1.0.1/c-ares/config.sub \
&& pip install/gevent-1.0.1

# Install Registry
RUN pip Install file:///docker-registry#egg=docker-registry[bugsnag,newrelic,cors]

RUN patch \
$ (python-c ' import boto; import os; print Os.path.dirname (boto.__file__) ')/connection.py \
</docker-registry/contrib/boto_header_patch.diff

ENV docker_registry_config/docker-registry/config/config_sample.yml
ENV Settings_flavor Dev

EXPOSE 5000

CMD ["Docker-registry"]

You can see the last sentence of Cmd ["Docker-registry"], here it is.

So how does this command start the registry service? into the registry container.
[Email protected]:/# which docker-registry
/usr/local/bin/docker-registry

[Email protected]:/# cat/usr/local/bin/docker-registry
#!/usr/bin/python
# easy-install-entry-script: ' Docker-registry==1.0.0-dev ', ' console_scripts ', ' docker-registry '
__requires__ = ' Docker-registry==1.0.0-dev '
Import Sys
From pkg_resources import Load_entry_point

if __name__ = = ' __main__ ':
Sys.exit (
Load_entry_point (' Docker-registry==1.0.0-dev ', ' console_scripts ', ' Docker-registry ') ()
)
Here is a Python method, not very clear, you can refer to the article
Http://blog.sina.com.cn/s/blog_85998e380101bojs.html
Http://www.cnblogs.com/babykick/archive/2012/03/09/2387808.html
Keep looking down.

[Email protected]:/# cat/usr/local/lib/python2.7/dist-packages/docker_registry-1.0.0_dev-py2.7.egg-info/ Entry_points.txt
[Console_scripts]
Docker-registry = Docker_registry.run:run_gunicorn
In this case, we probably know what's going on, and it's actually called the Run_gunicorn method of run.py.

[email protected]:/# cat/usr/local/lib/python2.7/dist-packages /docker_registry/run.py
def Run_gunicorn ():

args = [

'--access-logfile ', Env.source (' Gunicorn_access_log_file '),
"-- Error-logfile ', Env.source (' Gunicorn_error_log_file '),
'--max-requests ', ' n ',

'--graceful-timeout ', Env.source (' Gunicorn_graceful_timeout '),
'-T ', Env.source (' Gunicorn_silent_timeout '),
'-W ', Env.source (' gunicorn_workers '),
'-B ', address,
"

......

args + = Env.source (' gunicorn_opts ')
Args.append (' docker_registry.wsgi:application ')
# stringify all args and call
Os.execl (*[str (v) for V in Args])

Run_gunicorn () called the Gunicorn program, the host on the PS when you can see that the registry container launched 5 Gunicorn process.
Root 17466 0.0 0.9 21504 19264? Ss Dec09 0:00/usr/bin/python/usr/local/bin/gunicorn--access-logfile---error-logfil
Root 17480 1.2 2.2 48896 45888? S Dec09 15:37/usr/bin/python/usr/local/bin/gunicorn--access-logfile---error-logfil
Root 17481 1.2 2.2 48960 46080? S Dec09 15:34/usr/bin/python/usr/local/bin/gunicorn--access-logfile---error-logfil
Root 17482 1.2 2.2 49088 46080? S Dec09 15:35/usr/bin/python/usr/local/bin/gunicorn--access-logfile---error-logfil
Root 17483 1.2 2.2 49664 46720? S Dec09 15:34/usr/bin/python/usr/local/bin/gunicorn--access-logfile---error-logfil


Resources
Gunicorn-python WSGI HTTP Server for UNIX
www.gunicorn.org

Preliminary analysis of Docker Registry service start-up process

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.