This topic describes how to deploy Docker on CentOS.


You must have registered an Alibaba Cloud account before you follow the instructions provided in the tutorial. If not, create a new Alibaba Cloud account first.

Background information

This topic is applicable to developers that are familiar with Linux but new to Alibaba Cloud ECS.

In the following example, the operating system version is CentOS 7.2 64 3.10.0-514.6.2.el7.x86_64.
Note Docker requires a 64-bit Linux system with kernel 3.10 or later.


To build Docker on an ECS instance, perform the following steps:
  1. Deploy Docker
  2. Use Docker
  3. Create an image

Deploy Docker

You can purchase the required image from Alibaba Cloud Marketplace, and easily deploy Docker. You can also install Docker manually as described in this topic.

To deploy Docker, perform the following steps:

  1. Add a Yellowdog Updater, Modified (YUM) repository:
    yum install epel-release -y
    yum clean all
    yum list
  2. Install and run Docker:
    yum install docker-io -y
    systemctl start docker
  3. Check the installation result:
    docker info
    If the following information is displayed, Docker has been installed.Installation result

Use Docker

You can use Docker in these ways:
  1. Manage the Docker daemon:
    systemctl start docker     #Run the Docker daemon.
    systemctl stop docker      #Stop the Docker daemon.
    systemctl restart docker   #Restart the Docker daemon.
  2. Manage images. The following example uses Apache images from Alibaba Cloud image repository:
    docker pull
    • Modify the tag of an image in Alibaba Cloud image repository to simplify image identification:
      docker tag aliweb:v1
    • Check existing images:
      docker images
    • Delete an image:
      docker rmi -f
  3. Manage containers:
    • Enter a container. Run the docker images command to obtain the ImageId value of e1xxxxxxxxxe. Then, run the docker run command to enter the container.
      docker run -it e1xxxxxxxxxe /bin/bash
    • Exit the container. Run the exit command to exit the container.
    • You can combine the run command with the –d parameter to run the container in the background. The --name parameter specifies apache as the container name.
      docker run -d --name apache e1xxxxxxxxxe
    • Enter the container that runs in the background:
      docker exec -it apache /bin/bash
    • Create an image from the container. Description of the parameters in the command:docker commit <container ID or container name> [<repository name> [: <tag>]].
      docker commit containerID/containerName repository:tag
    • To easily test and restore an image, you can run the source image, create a new image with a simple name from the source image, and then test the new image.
      # docker commit 4c8066cd8c01 apachephp:v1
    • Run the container and map port 8080 of the host to the container:
      # docker run -d -p 8080:80 apachephp:v1

      In a browser, enter the IP address of the host followed by the port number 8080 to connect to the container. The following response indicates that the container runs normally.

      Mapping result

Create an image

To create an image, perform the following steps:

  1. Prepare the following content in a Dockerfile:
    # vim Dockerfile 
    FROM apachephp:v1  #Declare a base image.
    MAINTAINER DTSTACK #Declare the image owner.
    RUN mkdir /dtstact #The commands that you want to run before the container starts. You must add these commands to the end of the RUN command. The Dockerfile can contain only a maximum of 127 lines. If you have commands that exceed 127 lines in the Dockerfile, we recommend that you write these commands to a script.
    ENTRYPOINT ping #The commands that run at startup. The last command must be a frontend command that runs constantly. Otherwise, the container will exit after running all commands.
  2. Build an image:
    docker build -t webcentos:v1 .   #The single dot (.) specifies the path of the Dockerfile and must be provided.
    docker images                    #Check whether the image has been created.
    docker run -d webcentos:v1       #Run the container in the background.
    docker ps                        #Query the container in operation.
    docker ps -a                     #Query all containers including those in the stopped state.
    docker logs CONTAINER ID/IMAGE   #Check the startup log to troubleshoot the issue based on the container ID or name if the started container does not exist in the query result.
    docker commit fb2844b6c070 dtstackweb:v1 #The container ID and the name and version of the new image. You must add the information to the end of the commit command.
    docker images                    #Query images that have been downloaded and created on premises.
    docker push                      #Push an image to the remote image repository. Default value: Docker Hub.
  3. Push the image to the registry.

    Specify ImageId and image version.

    docker login --username=dtstack_plus #Specify the password of the image repository. Enter the information after you run this command.
    docker tag [ImageId][Image version]
    docker push[Image version]

    If you can view the image version in the image repository, it indicates that the image has been pushed to the registry.