Home > Article > Operation and Maintenance > How to use docker after installing it
In recent years, Docker has been widely used in software development and deployment. It provides a containerized technical solution and brings great convenience to developers and operation and maintenance personnel. After installing Docker, we need to know how to use it to build, run and manage containers. The following details how to use Docker after installing it.
1. Start Docker
After installing Docker, we need to start the Docker service. In the Linux system, you can use the following command to check whether it has been started:
systemctl status docker
If it is displayed active (running), it means that Docker has been started, otherwise it can be started by the following command:
sudo systemctl start docker
2. After starting Docker using Docker
, we can use Docker to build, run and Manage containers. Docker provides many command line tools. Here are some commonly used ones:
docker pull is used to obtain images from the Docker warehouse. Its command format is as follows:
docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Among them, OPTIONS is optional and can be used to specify which warehouse to obtain the image from and which authentication method to use; NAME is the image name, which can include the private warehouse address, and TAG is the label of the image, which is optional ;DIGEST is the hash value of the image and can also be used to identify the image. The sample command is as follows:
docker pull ubuntu:18.04
docker run is used to create and start the container. The command format is as follows:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Among them, OPTIONS is optional, and the following are commonly used:
IMAGE is the image name, COMMAND is the command to be run when starting the container, and ARG is the parameter of the command. The example command is as follows:
docker run -it --rm --name ubuntu_test ubuntu:18.04 /bin/bash
docker ps is used to list currently running containers. The command format is as follows:
docker ps [OPTIONS]
Among them, OPTIONS is optional, and the following are commonly used:
The sample command is as follows:
docker ps -a
docker logs is used to view the logs of the container. The command format is as follows:
docker logs [OPTIONS] CONTAINER
Among them, OPTIONS is optional, and the following are commonly used:
CONTAINER is the container name or ID. The example command is as follows:
docker logs -f ubuntu_test
docker stop is used to stop a running container. The command format is as follows:
docker stop [OPTIONS] CONTAINER [CONTAINER...]
Among them, OPTIONS is optional, and the following are commonly used:
The sample commands are as follows:
docker stop ubuntu_test
3. Summary
Docker provides a wealth of command line tools, making it very simple to build, run and manage containers. . This article introduces common commands of Docker and hopes to provide a reference for readers. When using Docker, you need to pay attention to security and performance issues. For example, when making an image, you should try to avoid installing too many software packages in it. At the same time, you should specify the resource limit of the container when starting the container to prevent the container from occupying too many resources and causing system performance degradation.
The above is the detailed content of How to use docker after installing it. For more information, please follow other related articles on the PHP Chinese website!