Home Operation and Maintenance Docker How to use docker after installing it

How to use docker after installing it

Apr 18, 2023 am 09:48 AM

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
Copy after login

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
Copy after login

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:

  1. docker pull

docker pull is used to obtain images from the Docker warehouse. Its command format is as follows:

docker pull [OPTIONS] NAME[:TAG|@DIGEST]
Copy after login

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
Copy after login
  1. docker run

docker run is used to create and start the container. The command format is as follows:

docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Copy after login

Among them, OPTIONS is optional, and the following are commonly used:

  • -d runs the container in the background and returns the container ID;
  • -it runs the container in interactive mode, usually used with -t and -i;
  • -p maps the container internal port to the host port;
  • --name specifies a name for the container ;
  • --restart Set the restart strategy of the container.

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
Copy after login
  1. docker ps

docker ps is used to list currently running containers. The command format is as follows:

docker ps [OPTIONS]
Copy after login

Among them, OPTIONS is optional, and the following are commonly used:

  • -a Lists all containers, including stopped containers;
  • -q List only the container IDs.

The sample command is as follows:

docker ps -a
Copy after login
  1. docker logs

docker logs is used to view the logs of the container. The command format is as follows:

docker logs [OPTIONS] CONTAINER
Copy after login

Among them, OPTIONS is optional, and the following are commonly used:

  • -f real-time output log;
  • -t display Timestamp;
  • --tail displays the last few logs.

CONTAINER is the container name or ID. The example command is as follows:

docker logs -f ubuntu_test
Copy after login
  1. docker stop

docker stop is used to stop a running container. The command format is as follows:

docker stop [OPTIONS] CONTAINER [CONTAINER...]
Copy after login

Among them, OPTIONS is optional, and the following are commonly used:

  • -t Set the timeout.

The sample commands are as follows:

docker stop ubuntu_test
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use docker exec to run commands in a Docker container How to use docker exec to run commands in a Docker container Mar 05, 2025 pm 03:42 PM

This article explains how to use the docker exec command to run commands within a running Docker container. It covers basic syntax, options (like -it for interactive use and -d for detached mode), shell access, common use cases (debugging, administr

What is docker for? What is docker for? What is docker for? What is docker for? Mar 05, 2025 pm 03:49 PM

This article explains Docker, a containerization platform simplifying application building, shipping, and running. It addresses the "it works on my machine" problem by packaging apps and dependencies into isolated containers, improving con

Is docker an environment or software Is docker an environment or software Mar 05, 2025 pm 03:38 PM

This article explains Docker, contrasting it with virtual machines. Docker uses containerization, sharing the host OS kernel for lightweight, resource-efficient application isolation. Key advantages include speed, portability, ease of deployment, a

How do I deploy applications to a Docker Swarm cluster? How do I deploy applications to a Docker Swarm cluster? Mar 17, 2025 pm 04:20 PM

The article details deploying applications to Docker Swarm, covering preparation, deployment steps, and security measures during the process.

What is docker for? What is docker for? What is docker for? What is docker for? Mar 05, 2025 pm 03:46 PM

Docker simplifies application building, shipping, and running via containerization. It offers consistent development environments, faster cycles, improved collaboration, and streamlined CI/CD, resulting in portable, scalable, and resource-efficient

What is docker for? What is docker for? What is docker for? What is docker for? Mar 05, 2025 pm 03:39 PM

This article explains Docker, a containerization platform simplifying application creation, deployment, and execution. It highlights Docker's benefits: improved efficiency, consistency, resource utilization, and streamlined deployment. Various use

What are Kubernetes pods, deployments, and services? What are Kubernetes pods, deployments, and services? Mar 17, 2025 pm 04:25 PM

The article explains Kubernetes' pods, deployments, and services, detailing their roles in managing containerized applications. It discusses how these components enhance scalability, stability, and communication within applications.(159 characters)

How do I scale applications in Kubernetes? How do I scale applications in Kubernetes? Mar 17, 2025 pm 04:28 PM

The article discusses scaling applications in Kubernetes using manual scaling, HPA, VPA, and Cluster Autoscaler, and provides best practices and tools for monitoring and automating scaling.

See all articles