You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Building applications
Setting up Docker
Copy page
Download PDF
Setting up Docker
This topic describes how to deploy Docker CE on Linux instances, as well as common Docker operations and the image creation process.​
About Docker​
Docker is an open-source application container engine. It packages applications and their dependencies into virtual containers, which can run on any computer with Linux, Windows, or macOS. This capability allows applications to operate seamlessly across diverse environments, including local systems, public clouds, and private clouds. For more information, visit Docker docs.​
The following items describe the main components of Docker:​
  • Docker client​
  • Docker Daemon​
  • Docker image​
  • Docker container​
Prerequisites​
  • The ECS instance status is Running.​
Procedure​
Install Docker​
​
veLinux 1.0/veLinux 2.0
CentOS 7.x/Stream 8/Stream 9
Ubuntu 18.04/20.04/22.04/24.04
Debian 10/11/12
​
  1. Execute the following command to install the packages that allow APT to use software repositories over HTTPS:​
  • ​
    sudo apt install -y ca-certificates curl gnupg lsb-release​
    ​
  1. Execute the following command to add the official Docker GPG key.​
  • ​
    sudo mkdir -p /etc/apt/keyrings​
    curl -fsSL https://mirrors.ivolces.com/docker/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg​
    ​
  1. Execute the following command to add the Docker software repository information.​
  • ​
    veLinux 1.0
    veLinux 2.0
    ​
    ​
    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.ivolces.com/docker/linux/debian buster stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null​
    ​
    ​
    ​
  1. Execute the following command to update the software repository.​
  • ​
    sudo apt update​
    ​
  1. Execute the following command to install Docker CE.​
  • ​
    sudo apt install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin​
    ​
  1. Execute the following command to run Docker.​
  • ​
    systemctl start docker​
    ​
  1. Execute the following command to check whether Docker is installed as expected.​
  • ​
    docker info​
    ​
  • If the output is as shown below, Docker has been successfully installed.​
  • ​​​
​
Use Docker​
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.​
​
Manage mirror sites​
When image pulls from the official Docker repository fail, you can configure one or multiple reliable and available mirror sites. Docker will pull images from the mirror site you specify, improving pull reliability and speed.​
  1. Edit the Docker configuration file.​
  • ​
    sudo vim /etc/docker/daemon.json​
    ​
  1. Press i to enter edit mode, and enter the mirror site you need in the registry-mirrors structure.​
tip​
Replace https://registry-1.docker.io and https://registry-2.docker.io with the mirror sites you need. Separate multiple sources with ,.​
  • ​
    {​
    "registry-mirrors": [​
    "https://registry-1.docker.io",​
    "https://registry-2.docker.io"​
    ]​
    }​
    ​
  1. Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.​
  1. Execute the following command to restart the Docker service.​
  • ​
    sudo systemctl daemon-reload && sudo systemctl restart docker​
    ​
Manage images​
  • Pull images​
  • In the example provided in this topic, the Ubuntu image is used.​
  • ​
    docker pull ubuntu​
    ​
  • View the existing images​
  • ​
    docker images​
    ​
  • ​alt​​
  • Forcibly delete an image​
  • ​
    docker rmi -f ubuntu​
    ​
  • After you delete an image, you can execute the docker images command to check whether the image is deleted.​
  • ​alt​​
Manage containers​
  • Enter a container​
  • ​
    docker run -it <ImageId> /bin/bash​
    ​
  • You can execute the docker images command to get <ImageId> in the preceding command.​
  • Exit a container​
  • Execute the exit command to exit the current container.​
  • Run a container in the background​
  • ​
    docker run -d --name ubuntu ImageId​
    ​
tip​
The --name option specifies ubuntu as the container name.​
  • Enter a container running in the background​
  • ​
    docker exec -it <Container ID> /bin/bash​
    ​
tip​
Replace <Container ID> with the actual container ID, which you can obtain by executing the docker ps command.​
  • Create an image from a container​
  • ​
    docker commit <Container ID OR Container Name> [<Repository Name>[:<Tags>]]​
    ​
tip​
Replace <Container ID OR Container Name> with the actual container ID or name, <Repository Name> with the actual repository name, and <Tags> with the actual repository tags. Example: docker commit 097fdd5e**** dockertest/ubuntu:latest.​
Create an image​
  1. Execute the following command to create and edit a Dockerfile.​
  • ​
    vim Dockerfile​
    ​
  1. Press i to enter edit mode and add the following content.​
  • ​
    FROM nginx​
    RUN echo '<h1>Hello, Docker!</h1>' > /usr/share/nginx/html/index.html​
    ​
  • The following items describe simple instructions in the Dockerfile. For more information, visit the official website.​
  • FROM statement: Indicates that the Nginx image is used as the base image. In a Dockerfile, the FROM instruction is required and must be the first instruction.​
  • RUN statement: The format is RUN <command>. For example, if the command in the statement is echo "Hello, Docker!", Hello, Docker! is displayed after you execute the statement.​
  1. Press the Esc key, enter :wq, and then press Enter to save and exit the Dockerfile.​
  1. Execute the following command to create an image.​
  • ​
    docker build -t nginx:v1 . # . specifies the path to the Dockerfile and cannot be omitted.​
    docker images # Check whether the image is created.​
    ​
  • ​alt​​
  1. Execute the following commands to run and view the containers.​
  • ​
    docker run -d nginx:v1 # Run containers in the background.​
    docker ps # View currently running containers.​
    docker ps -a # View all containers, including containers that are not running.​
    docker logs CONTAINER ID/NAMES # If no running containers are displayed, use the container ID or name to check the startup logs for troubleshooting purposes.​
    ​
  1. Execute the following command to create an image.​
  • ​
    docker commit bd0d3e7e**** nginxtest:v1 # Add the container ID, along with the name and version number of the new image, after the commit parameter.​
    docker images # List local (downloaded and locally created) images.​
    ​
  1. Push the image to the remote repository.​
  • By default, the image is pushed to Docker Hub. You need to first log in to Docker, associate tags with the image, and name the image in the format of [Docker User Name]/[Image Name]:[Tag]. The push is complete.​
  • ​
    docker login​
    docker tag [ImageId] [Docker User Name]/[Image Name]:[Tag]​
    docker push [Docker User Name]/[Image Name]:[Tag]​
    ​
tip​
Replace [Docker User Name] with your actual Docker username, [Image Name] with the actual image name, and [Tag] with the actual image tag.​
  1. Log in to Docker Hub to view the image.​
  • ​image​​
​
Last updated: 2026.06.18 17:48:26