百度智能云

All Product Document

          Cloud Container Engine

          Basic Operation of Image Repository

          Introduction

          The image warehouse provides you with a safe, reliable and easy-to-use container image hosting service, which can reduce the construction and operation costs of Registry, improving the deliver capabilities and experiences of cloud native application.

          You can use the image warehouse feature provided by the Cloud Container Engine CCE Cloud Container Engine-Image Warehouse

          You can also use the CCR container image service console with more perfect features and experiences

          Note This document is only for the image warehouse in the cloud container engine CCE. The domain name of the image warehouse is hub.baidubce.com . To refer to this document for using the cloud container image service CCR, please replace the domain name of the image warehouse with registry.baidubce.com .com.

          Open Image Library

          When you first enter the image library, the page as shown in the following figure pops up. Fill in the user name and set a password according to requirements.

          Note:

          User name: The naming rules for user names of image library are: The user name only supports lowercase letters and numbers, with a length of 4-30, and cannot be modified after being submitted.

          Password: The password is a token for users to log in to the docker image library. Password creation rules: A password contains 8-32 characters among which English, numbers and symbols must coexist, and the symbols are only limited to!. @#^\*().

          Create Namespace

          1.Select the name space under the image library classification, and then click "Create Name Space" in the name space list.

          2.Fill in the space name to be created and select the space type. Then click "Confirm" to create the name space.

          Note

          The naming rules of the name space are: length: 1-65, lowercase letters, numbers, and -\_. special characters. The special characters cannot appear in the start and end, or appear consecutively.

          (Optional) Create Image

          1.Click the "Create" button in the image list page.

          2.Select the name space, fill in the image name and version number, and then click "Confirm".

          Note:

          1.The naming of the image name should conform to: "length: 1-65, lowercase letters, numbers, and -_/. special characters. The special characters cannot appear in the start and end, or appear consecutively".

          2.The naming of the version number should conform to: "length: 1-65, lowercase letters, numbers, and -_/. special characters. The special characters cannot appear in the start and end, or appear consecutively".

          3.If the users don't select to create an image, the basic information above is also generated automatically after the image is pushed to the corresponding name space.

          Delete Image

          Select the image name to be deleted, then click the "Delete" button. Click "Confirm" in the pop-up deletion prompt.

          Note The deleted image cannot be recovered and used.

          Push the Image to the Image Library

          Note This document is only for the image warehouse in the cloud container engine CCE. The domain name of the image warehouse is hub.baidubce.com . To refer to this document for using the cloud container image service CCR, please replace the domain name of the image warehouse with registry.baidubce.com .com.

          Log in to cloud platform image library

              >$ sudo docker login --username=[username] hub.agilecloud.com 

          username: name of image library, namely, the user name to be filled in when the image library is opened. Enter the password to log in.

          Upload image

              $ sudo docker tag [ImageId]hub.agilecloud.com/[namespace]/[ImageName]:[Image Version No.] 
              $ sudo docker push hub.agilecloud.com/[namespace]/[ImageName]:[Image Version No.] 
          • The ImageId and image version number are supplemented according to the image information.
          • The namespace is the name space to be filled in when the image library is opened.
          • The ImageName is the image name created in the console.

          Download image

          To log in to the image library, you should enter the password.

              $ sudo docker pull hub.agilecloud.com/[namespace]/[ImageName]:[Image Version No.] 

          Delete image

          Select the image, click "Delete" and confirm.

          Note

          The deleted image cannot be recovered and used. Please confirm to make a backup before deletion.

          Use the DockerHub Accelerator

          How to use the DockerHub image accelerator?

          Docker software source address: https://mirror.agilecloud.com

          Baidu Cloud Compute of CCE cluster

          The manual configuration is not required. When a node is created, the docker services are installed automatically to configure the Mirror image. The configuration items are as below:

              [root@VM_1_2_centos ~]# cat /etc/systemd/system/docker.service 
              IPTABLES="--iptables=false" 
              STORAGE_DRIVER="--storage-driver=overlay2"
              IP_MASQ="--ip-masq=false" 
              LOG_LEVEL="--log-level=warn" 
              REGISTRY_MIRROR="--registry-mirror=https://mirror.agilecloud.com"

          Baidu Cloud Compute and server configuration

          Linux:

          1.It is applicable to Ubuntu 14.04, Debian, CentOS6, Fedora and OpenSUSE, and other versions may be slightly different.

          Modify the docker configuration file/etc/default/docker as below:

               DOCKER_OPTS="--registry-mirror=https://mirror.agilecloud.com"

          2.It is applicable to Centos7.Modify the Docker configuration file/etc/sysconfig/docker, and add the following

              OPTIONS='--registry-mirror=https://mirror.agilecloud.com' 

          Note

          Only the versions higher than Docker 1.3.2 support the Docker Hub Mirror mechanism. If you haven't installed Docker or your version is too low, please install the Docker or upgrade your version.

          Windows

          If you use the Boot2Docker, the configuration command is: Enter Boot2Docker Start Shell, and execute

              sudo su echo "EXTRA_ARGS=\"every registry- 
              mirror=http://https://mirror.agilecloud.com"">> /var/lib/boot2docker/profile  exit #  Restart Boot2Docker. 

          Start docker

          Execute the following commands to start docker.

              sudo service docker start 

          Construct Docker Image

          DockerHub has provided developers with a large number of excellent available images. View Official Website of DockerHub for details.

          Due to the diversity of actual scenarios, not all applications can find the corresponding images for use. You can learn how to construct a personalized Docker image by the following tutorials.

          Currently, there are two modes for Docker to generate an image:

          • Automatically construct images by Dockerfile;
          • Execute Commit command on the existing container to pack and generate images.

          Generate images by Dockerfile automatic compilation

          Take the WordPress provided officially by Dockerhub for example, and switch to github view details.

          The related Dockfile sound codes are as follows:

                  FROM php:5.6-apache 
                  
                  # install the PHP extensions we need 
                  RUN apt-get update && apt-get install -y libpng12-dev libjpeg-dev && rm -rf /var/lib/apt/lists/* \ 
                      && docker-php-ext-configure gd --with-png-dir=/usr --with-jpeg-dir=/usr \ 
                      && docker-php-ext-install gd mysqli opcache 
                  
                  # set recommended PHP.ini settings 
                  # see https://secure.php.net/manual/en/opcache.installation.php 
                  RUN { \ 
                          echo 'opcache.memory_consumption=128'; \ 
                          echo 'opcache.interned_strings_buffer=8'; \ 
                          echo 'opcache.max_accelerated_files=4000'; \ 
                          echo 'opcache.revalidate_freq=2'; \ 
                          echo 'opcache.fast_shutdown=1'; \ 
                          echo 'opcache.enable_cli=1'; \ 
                      } > /usr/local/etc/php/conf.d/opcache-recommended.ini 
                  
                  RUN a2enmod rewrite expires 
                  
                  VOLUME /var/www/html 
                  
                  ENV WORDPRESS_VERSION 4.6.1 
                  ENV WORDPRESS_SHA1 027e065d30a64720624a7404a1820e6c6fff1202 
                  
                  RUN set -x \ 
                      && curl -o wordpress.tar.gz -fSL "https://wordpress.org/wordpress-${WORDPRESS_VERSION}.tar.gz" \ 
                      && echo "$WORDPRESS_SHA1 *wordpress.tar.gz"|  sha1sum -c - \ 
                  # upstream tarballs include ./wordpress/ so this gives us /usr/src/wordpress 
                      && tar -xzf wordpress.tar.gz -C /usr/src/ \ 
                      && rm wordpress.tar.gz \ 
                      && chown -R www-data:www-data /usr/src/wordpress 
                  
                  COPY docker-entrypoint.sh /usr/local/bin/ 
                  RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat 
                  
                  # ENTRYPOINT resets CMD 
                  ENTRYPOINT ["docker-entrypoint.sh"] 
                  CMD ["apache2-foreground"] 

          The above Dockerfile file describes how to construct the basic environment required by WordPress applications.

          Create a file folder at the terminal to save the Dockerfile file, and construct images by the docker build command.

              [root@instance-hlf45x1g-1 worldpress]# docker build ./ 
              Sending build context to Docker daemon 3.072 kB 
              Step 1 : FROM php:5.6-apache 
              Trying to pull repository docker.io/library/php ... 
              5.6-apache: Pulling from docker.io/library/php 
              386a066cd84a: Pull complete 
              269e95c6053a: Pull complete 
              ......

          View the constructed image by the docker images command.

              [root@instance-hlf45x1g-1 worldpress]# docker images 
              REPOSITORY                                     TAG                 IMAGE ID            CREATED             SIZE 
              worldpress                                     latest              9f0b470b5ddb        13 minutes ago      420 MB 
              docker.io/php                                  5.6-apache          eb8333e24502        7 days ago          389.7 MB 

          When Dockerfile is used to construct an image, the following recommendations are provided:

          • Select the basic image officially provided by Docker as the baseline as far as possible.
          • Select the general and universal orders among the first lines of the orders of Dockerfile to install and operated related dependency software, so as to efficiently use the cache.
          • Only the necessary software package is installed to reduce the image size.
          • Multiple RUN commands are connected by '\' to facilitate understanding and convenient maintenance.
          • Construct images by -t labels to facilitate the management of created images.
          • The clear comments improve the readability.
          • After an image is constructed, please locally start verification of its functionality.

          Execute commit to pack and generate images

          Images can be constructed quickly by Dockerfile, while solutions are provided for the existing container image by the commit.

          The construction of images by commit is as follows:

          1.Run and enter the container based on base images.

              [root@instance-hlf45x1g-1 ~]# docker run -i -t centos 

          2.Install the required software and add the configuration.

                  [root@c4f1basa4w76 /]# yum update && yum install  openssh-server 
                  Loaded plugins: fastestmirror, ovl 
                  base                                                                                                                                                                  |  3.6 kB  00:00:00     
                  extras                                                                                                                                                                |  3.4 kB  00:00:00     
                  updates                                                                                                                                                               |  3.4 kB  00:00:00     
                  (1/4): base/7/x86_64/group_gz                                                                                                                                         |  155 kB  00:00:00     
                  (2/4): extras/7/x86_64/primary_db                                                                                                                                     |  166 kB  00:00:00     
                  (3/4): base/7/x86_64/primary_db                                                                                                                                       |  5.3 MB  00:00:00     
                  (4/4): updates/7/x86_64/primary_db 
                  ......
                  ......
                  ......
                  Dependency Installed: 
                  fipscheck.x86_64 0:1.4.1-5.el7     fipscheck-lib.x86_64 0:1.4.1-5.el7              openssh.x86_64 0:6.6.1p1-25.el7_2  tcp_wrappers-libs.x86_64 0:7.6-77.el7 

          3.After configuration, open the new terminal to save the image.

              [root@instance-hlf45x1g-1 ~]# docker ps 
                  CONTAINER ID    IMAGE       COMMAND       CREATED          STATUS        PORTS       NAMES 
                  c4f1basa4w76   centos     "/bin/bash"   13 minutes ago   Up 13 minutes            fashion_surl 
              [root@instance-hlf45x1g-1 ~]# docker commit c4f1basa4w76 my_centos:1.0      
                  sha256:65325ffd2af9d574afca917a8ce81cf8a710e6d1067ee611a87087e1aa88e4a4
              [root@instance-hlf45x1g-1 ~]# docker images 
                  REPOSITORY      TAG       IMAGE ID            CREATED             SIZE 
                  my_centos       1.0     65325ffd2af9        16 seconds ago      307.8 MB 
          Previous
          Privilege Management
          Next
          Build Services by Container Image