Installing Docker
Introduction
Docker is an open-source application container engine that features portability, scalability, high security, and manageability. Developers can package an application and its dependencies into a portable container and run the container on a Linux server to build, deploy, and manage the application more efficiently. This section describes how to install Docker in HCE.
Preparations
Prepare an ECS.
Prerequisites
A local yum repository has been configured. For details, see Configuring an HCE Repository.
Procedure
- Install Docker.
- Install Docker.
dnf install docker
- Install Docker.
- Verify that Docker is installed.
- Start Docker.
systemctl start docker
- Check the Docker version. If a version is displayed, Docker is installed successfully.
docker -v
Figure 1 Checking whether Docker is installed successfully
- Start Docker.
Docker 18.09.0 is installed. To install a later version, see Docker Documentation.
Using Docker
- Manage the Docker daemon.
- Run the daemon.
systemctl start docker
- Stop the daemon.
systemctl stop docker
- Restart the daemon.
systemctl restart docker
- Run the daemon.
- Manage images. The nginx image is used as an example. You need to prepare a local image file nginx_latest.tar.
- Import the image.
docker load -i <nginx_latest.tar file path>
- Change the image tag.
# Change the tag of the nginx image from latest to v1. docker tag nginx:latest nginx:v1
- Check existing images.
docker images
- Delete the image.
docker rmi nginx:v1
- Import the image.
- Manage containers.
- Start a container.
# Create and start a container from an image. The image ID can be obtained by running docker images. docker run -it <image-ID> /bin/bash
- Exit a container.
exit
- Start a container in the background.
docker run -itd <image-ID>
- Check all running containers.
docker ps
- Enter a container running in the background. You can run docker ps to obtain the container ID.
docker exec -it <Container ID> /bin/bash
- Create an image from the container. The container ID can be obtained by running docker ps.
docker commit <Container ID> [<Repository name>[:<Tag>]]
Example:
docker commit 135****9f757 nginx:v1
- Start a container.
System Power-Loss Impacts
If a host is powered off unexpectedly, or if there is a kernel panic, there is no time for the states managed by the Docker daemon to be flushed to disk. As a result, when the system starts back up again, the states that Docker daemon reads from disk are no longer current. Possible problems include but are not limited to the following:
- After the system is started again, docker ps -a does not show containers created before the power-loss, as the state files of the containers were not flushed to disk. As a result, the daemon cannot obtain the latest container states after the system is started again. (Similar problems may occur on images, volumes, and networks.)
- If a file is being written when the host is powered off unexpectedly, after the system is started again, the daemon reloads the file and finds that the file format is invalid or the file content is incomplete, resulting in loading errors.
- If a Docker DB is damaged due to a sudden power-loss, the DB file in the data-root directory will be removed when the system is started again. The following information will be deleted:
- Resources created using docker network.
- Resources created using docker volume.
- Caches.
- containerd metadata. Starting a container will rebuild its containerd metadata.
If you want to manually clear the environment, you can set the environment variable DISABLE_CRASH_FILES_DELETE=true for the Docker daemon, and then the DB file will not be automatically removed when the system is re-started again after a power-loss.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot