Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the basic commands of Docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you "what are the basic commands of Docker", the content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn this article "what are the basic commands of Docker?"

One: Overview

Use docker or docker help to view all the commands of docker. Use the docker command-- help to view the details of the command.

Two: command introduction

1. Info,version

View the environment and version information of docker

two。 Container life cycle management

The Docker run command is used to create a container based on a specific image and to control the container based on options.

-- name: give the container a name. Without this option, Docker defaults to assigning a name to the container.

-- I: use exchange mode and always maintain input stream development

-- t: assign a pseudo terminal to interact

For example: docker run-ti-name myCentos centos:latest / bin/bash

-- d (--detach=false) specifies whether the container runs in the foreground or backstage false foreground by default

For example, docker run-d centos:latest ping www.baidu.com, this container will be executed permanently in the background because the ping thread will not stop.

-- restart launch policy when a container is launched. Default is' no''.

Such as: docker run-d-restart=always centos:latest ping www.baidu.com

-u (--user= "") specifies the user of the container

-a (--attach= []) login container (must be a container running in the background started with docker run-d)

Such as: docker run-it-d centos this container execution, will automatically execute the default thread "/ bin/bash", but will not let you immediately enter the console operation. It will be executed in the background, and you can see the currently running console with docker ps. You can enter the container using docker attach "container name or ID". But it has one drawback: as soon as the connection is terminated or the exit command is used, the container will exit the background.

Generally use docker exec to enter and exit to use exit

For example: docker exec-ti 8777* / bin/bash

-w (--workdir= "") specifies the working directory of the container

For example: docker run-ti-d-w / home/docker centos

If you enter the container to perform the touch a.txt operation, the file a.txt is located in the / home/docker directory in the container by default.

-c sets the container cpu weight, which is used in cpu sharing scenarios; the-c option will be discarded and-cpu-shares is recommended. The simple algorithm is that all the set values are added together, and the percentage of each container is the utilization of CPU. If there is only one container, the CPU utilization will be 100% regardless of whether it is set to 512 or 1024. Of course, if the host is 3core and runs three containers, two cpu-shares is set to 512 and one is set to 1024, then each container can occupy one of the 100% CPU

-m specifies the upper limit of the memory of the container

The default docker memory limit can be limited by using the-m parameter, but if only the-m parameter is added and nothing else is added, then the memory limit will not be dead. For example, if you have-m 256m memory, then the program in the container can run to 256m*2=512m before being killed by oom. But if you want to write dead memory, you can use-m 100m-- memory-swap=100m.

If you do not add the-- memory-swap option, it means that programs in the container can use 100m of memory and 100Mswap memory, and by default,-- memory-swap is set to twice the size of memory. -m is the upper limit of physical memory, and-memory-swap is the sum of memory + swap. When the pressure value is the upper limit of-memory-swap, the processes in the container will be directly OOM kill

-P exposes all container interfaces and maps randomly to the host

-p exposes the specified interface and host mapping

For example: docker run-d-- name=server-db-p 3306 centos6.8-mysql / usr/bin/mysql_safe-d when we specify that port 3306 of the server host is mapped to port 3306 of the container and exposed.

-h (--hostname= "") specifies the hostname of the container

-v (--volume= []) mounts the storage volume to the container and mounts it to a directory of the container.

3. Docker start/stop/restart command

The Docker run command can be used to create a new container to run, and for existing containers, you can start, stop, and restart with the above command.

4. Docker warehouse command

Docker registry is the repository where images are stored. Users can communicate with Docker registry through Docker client to complete image search, download, upload and other related operations.

Docker pull: pull images from docker repository, such as docker pull centos:latest

Docker push: push the local image to the repository

5. Mirror management

Docker images: lists the mirrors on the host. By default, only the top mirrors are listed. You can use the-an option to display all mirrors.

6. Docker rmi: used to delete an image. If a container launched based on this image already exists, it cannot be deleted directly. You need to delete the container first. Of course, you can force deletion through the-f option.

7. Docker attach connects to the running container

8. Docker inspect: view the details of images and containers. All the information is listed by default. You can specify the template format of the output through the-format parameter.

9. Docker ps: common options for viewing container-related information are-an and-l

10. Docker commit: solidifies a container into a new image. Such as installing specific tools in the container, save these changes through the commit command so that they are not lost due to the stop of the container.

11. Docker events: print real-time system events

12. Docker history: prints the historical version information of the specified image

13. Docker logs: print the running log of the processes in the container

14. Docker build: create a new image through Dockerfile

15. Docker cp: the copy of files or folders between the local file system and the container. Such as: docker cp / usr/local/src/c.txt 58188a80dbd8:/home/docker

16. Docker diff: view changes to the container file system

17. Docker create: create a container without starting it

18. Dockers export: export the container's file system to standard output in the format of a tar package.

19. Docker import: import container is an image

20. Docker kill: kill a running container

21. Docker login: log in to the docker warehouse

twenty-two。 Docker logout

23. Docker pause: stops all processes in the container

24. Docker search: search for images in the repository

25. Docker top: displays the processes running in the container

These are all the contents of this article entitled "what are the basic commands of Docker". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report