All Products
Search
Document Center

Simple Application Server:Deploy Docker by using a Docker application image

Last Updated:Dec 16, 2024

This topic describes how to deploy a Docker environment on a simple application server by using a Docker application image provided by Alibaba Cloud. This topic also describes how to use Docker to start an NGINX container.

Note
  • If you created a simple application server, you can use one of the following methods to deploy Docker:

    • Manually deploy Docker. For more information, see Deploy Docker.

    • Reset the simple application server and select a Docker application image to deploy Docker. Take note that the reset operation clears data from the disks attached to the simple application server. To prevent data loss, back up the disk data before you perform the reset operation. For more information, see Reset a simple application server.

  • For more information about Docker, see What is Docker?

Deploy Docker

  1. Log on to the Simple Application Server console.

  2. In the left-side navigation pane, click Servers.

  3. In the upper-left corner of the Servers page, click Create Server.

  4. On the Simple Application Server page, configure the parameters based on your business requirements.

    The following table describes the parameters.

    Parameter

    Description

    Example

    Region

    Select a region based on the geographical location of your business. The region cannot be changed after the simple application server is created. Proceed with caution.

    Important

    When you access simple application servers that reside in regions outside the Chinese mainland, such as China (Hong Kong) and Singapore, from regions within the Chinese mainland, high network latency may occur. We recommend that you select a region that is the closest to the geographical location of your end users to accelerate access. For more information, see Regions and network connectivity.

    China (Hong Kong)

    Image

    On the Apps Image tab, select Docker.

    image

    • Type: Apps Image

    • Application: Docker 26.1.3

    Instance Plan

    Select a plan based on your business requirements. You are charged additional fees for outbound data transfers over the Internet that exceed the plan. For more information about the billing rules, see Billing overview.

    $3.5/mo

    Data Disk

    Specify the size of the data disk that you want to attach to the simple application server based on your business requirements. This parameter is optional.

    Important

    To use the data disk after the simple application server is created, you must create partitions and file systems on the data disk.

    0GB

    Subscription Time

    Select a subscription duration for the simple application server. You can select Auto-renewal based on your business requirements.

    1 Month

    Quantity

    Specify the number of simple application servers that you want to purchase. Default value: 1. You can create up to 20 simple application servers in a region.

    1

  5. Click Buy Now.

    Follow the on-screen instructions to complete the payment. When the status of the simple application server changes from Pending to Running, a Docker environment is deployed on the simple application server.

    image

  6. (Conditionally required) If you attach a data disk when you create the simple application server, you must create partitions and file systems on the disk before you can use the disk. For more information, see Partition and format the data disk.

Use Docker

  1. Log on to the Simple Application Server console.

  2. In the left-side navigation pane, click Servers.

  3. On the Servers page, find the simple application server that you created from the Docker application image and click the server ID.

  4. Click the Application Details tab to view the Docker usage steps, Docker information, and application installation information.

    image

  5. In the Docker Usage Procedure section, click Log on to the simple application server.

  6. In the Remote Connection dialog box, click Log on Now.

  7. Use Docker within the simple application server that you created.

    In the following example, Docker pulls an NGINX image and starts an NGINX container.

    1. Run the following command to pull the latest NGINX image among the searched NGINX images to the simple application server:

      sudo docker pull nginx
    2. Run the following command to query existing Docker images on the server:

      sudo docker images

      If the command output shown in the following figure is returned, the latest NGINX image is pulled to the simple application server.

      image

    3. Run the following command to create an NGINX container and run the container in the background. Configure the NGINX container to use port 80 of the server.

      sudo docker run --name <Container alias> -- network host -d <Image name> (REPOSITORY)

      In this example, the image name is set to nginx and the container alias is set to nginx-test01 Sample command:

      sudo docker run --name nginx-test01 --network host -d nginx
      Note

      You can run the docker images command to query the image name.

    4. Run the following command to query containers:

      sudo docker ps

      Sample command output:

      image

    5. Use a browser on your computer to access the <Public IP address of the simple application server>.

      If the following page appears, the NGINX container is deployed as expected. If you cannot access the NGINX container, use the following solutions:

      • Enable port 80 if port 80 is disabled on the simple application server. For more information, see Manage a firewall.

      • Change the default CIDR block of Docker if the CIDR block of Docker conflicts with the internal CIDR block. For more information, see FAQ.

      nginx

FAQ

Problem description

By default, the docker0 bridge is created when Docker is started. If the CIDR block of the docker0 bridge conflicts with the CIDR block of the internal eth0, the NGINX container may be inaccessible.

Solution

  1. Run the following command to check whether the CIDR blocks of docker0 and eth0 conflict with each other:

    route -n

    If the command output shown in the following figure is returned, the CIDR blocks of docker0 and eth0 conflict with each other.

    image

  2. Run the following command to stop Docker:

    sudo systemctl stop docker
  3. Run the following command to open the /etc/docker/daemon.json file:

    sudo vim /etc/docker/daemon.json

    Press the I key to enter Insert mode and add the following CIDR block information to the file:

    {
    "bip":"100.10.XX.XX/24"
    }
    Note

    100.10.XX.XX indicates the CIDR block. Replace the value with a CIDR block that is different from the eth0 CIDR block.

    Press the Esc key, enter :wq, and press the Enter key to save and close the file.

  4. Run the following command to reload the configuration file:

    sudo systemctl daemon-reload
  5. Run the following command to start Docker:

    sudo systemctl start docker
  6. Run the following command to check whether the modification takes effect:

    route

    If the command output shown in the following figure is returned, the CIDR block of docker0 is changed as expected. You can re-access the NGINX container.

    image