All Products
Search
Document Center

Simple Application Server:Use an application image to quickly deploy Docker

Last Updated:Oct 24, 2024

This topic describes how to deploy Docker on a simple application server that is created from a Docker application image provided by Alibaba Cloud and how to deploy an NGINX web server by using Docker.

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 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 and a Docker version.

    • Type: Apps Image

    • Version: Docker 20.10.7

    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, Docker is deployed.

    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.

  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, an NGINX image is pulled and run by using Docker.

    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. In the command, map port 80 of the NGINX container to port 8080 of the server.

      sudo docker run --name <Container alias> -p 8080:80 -d <Image name> (REPOSITORY)

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

      sudo docker run --name nginx-test -p 8080:80 -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. Allow port 8080 in the firewall of the simple application server. For more information, see Manage a firewall.

    6. Open a browser on your computer and enter <Public IP address of the simple application server>:8080 in the address bar to access the simple application server.

      If the following page appears, the NGINX web server is deployed as expected. If you cannot access the NGINX web server, the CIDR block of Docker may conflict with the internal CIDR block. To resolve the issue, change the default CIDR block of Docker. 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 network segment, the NGINX web server may be inaccessible.

Solution

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

    route

    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 web server.

    image