In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "what are the management operations of Docker". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what are the management operations of Docker"?
A container is an environment that packages applications and services. It is a lightweight virtual machine, and each container consists of a specific set of applications and necessary dependencies.
Special note: when using git-bash to run the docker command on windows, an error will be reported if the-I-t parameter is used:
$docker run-it-name my docker.io/centos
The input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
The error message clearly states that you want to use winpty to run it. That is:
Winpty docker run-it-- name my docker.io/centos
1. Container management operations
1.1 create a container
Common commands for containers include: create, view, start, terminate (stop), delete.
You can use docker create and docker run to create a container. The difference between them is that after docker create creates the container, the container is stopped, while docker run starts the container at the same time after creating the container (equivalent to: docker create-> docker start).
Docker create image names such as: docker create ubuntu / / without ": version number" will use the latest official image. Use docker ps to view currently running containers, and docker ps-a to view all containers, including running and not running containers.
Docker run can create interactive containers and backstage containers.
Docker run-I-t-- name=inspect_shell ubuntu / bin/bash / / will create an interactive container docker run-d-name=daemon_while ubuntu / bin/bash-c "while true;do echo hello world;sleep 1 done" / / will create a backstage container-- the name of the name parameter must be unique and cannot be repeated.
When creating a container, it will first search for whether the image exists locally. If it does not exist, download it from the public repository, otherwise create the container directly using the local image. The container's file system adds a read-write file layer to the read-only image file, and bridges the network interface to the host host by bridge, and then assigns an IP address to the virtual network interface.
1.2 View the container
You can use the docker ps command to follow different parameters. For more information, you can view help using docker ps-- help.
Docker ps / / only view the currently running containers docker ps-l / / list the last created containers docker ps-nailx / / check if the status in the last x containers is Exited, exit normally when the number in parentheses is 0, and all other values are abnormal exit.
1.3 start the container
Containers created with docker run are directly in the running state, while containers created with docker create need to be launched using docker start.
Docker start container ID or container name docker run-- restart=always-- name docker_restart-d ubuntu / bin/sh-c "while rue;do echo hello world;sleep 1 Done "docker run ubuntu echo" Hello docker "/ / immediately after the output of this container stops docker ps-a, you can look up the ID and name of the container. If you want to start this container again instead of creating a new container, you can use the following way: docker start-I container ID / / has a-I parameter, indicating that the output to the terminal can not be seen without the-I parameter.
If restart is always, you will attempt to restart the container regardless of the return code of the container. You can also set it to-- restart=on-failure:5 to set the number of reboot attempts when the return code is not 0.
1.4 termination Container
The normal exit container uses the docker stop container name or container ID, and you can use docker kill to force the exit of the container.
Docker stop container name or container IDdocker kill container name or container ID
1.5 Delete containers
Docker rm container ID or container name / / can only delete non-running containers docker rm-f container ID or container name / / forcibly delete. Running containers can delete docker rm `container-a-q` / / delete all containers in batches. The-Q parameter only lists the container's ID.
2. Information acquisition and command execution in the container
2.1 attachment Container
The attached container command can only be used in interactive containers, that is, containers running with the-I-t parameter can be attached to a number of terminals, and multiple terminal operations are synchronous, that is, what you enter in one terminal, what will also be displayed in the other terminals, withdraw from a terminal using exit exit, all attached terminals will exit.
Docker run-I-t ubuntu / bin/sh and then open another terminal and use docker attach ubuntu / / to enter the interactive interface, so there will be two terminals, and they are synchronized. At present, after entering this command, you must press enter twice before the interactive interface appears normally. Backstage containers cannot rely on terminals using this command. Ps: if you just want to enter a running container, and the container does not necessarily run with-I-t, you can use the following command: docker exec-it container ID or name bash
2.2 View the container log
The interactive container can directly enter and view the log by attaching the command, while the backstage container can view the container log through the docker logs command.
Docker run-d-- name = daemon_logs ubuntu / bin/bash-c "for ((item0 + +)); do echo $ipolitics sleep 1 poster;" / / Note here to use double quotes docker logs-f deamon_logs / /-f to view the container log in real time docker logs-f-- tail=x daemon_logs / / only view the last x-line log in real time docker logs-f-- tail=5-t daemon_logs / /-t to view the time generated by the log.
2.3 View Container process
Docker top can view the running processes in the container
Docker top container ID or container name
2.4 View Container Information
Docker inspect is used to view container configuration information, including container name, environment variables, run commands, host configuration, network configuration, and data volume configuration.
Docker inspect container ID or container name
For more information, please see help: docker inspect-- help
2.5 execute commands in the container
When the container starts, you usually need to specify the program that needs to be executed, but sometimes we need to start another program halfway after the container is running. Starting with Docker 1.3, we can use the docker exec command to run new tasks in the container. It creates two types of tasks: backstage tasks and interactive tasks.
Docker exec-d daemon_dave touch / etc/new_config_file / / backstage task docker exec-I-t daemon_dave / bin/bash / / interactive task, just like creating an interactive container. Note: all containers that run this command must be running
3. Import and export of containers
Users can not only submit the container to a public server, but also export the container to the local file system, and then re-import it into the Docker runtime environment when needed.
Container export:
Docker run-I-t-- name=inspect_import ubuntu / bin/bash then modify the container as needed, install the required software, etc., and then execute the following command to export to the local system. Docker export inspect_import > my_container.tar
Container Import:
Cat my_container.tar | docker import-imported:container//imported is the name of the image, and container is the image tag (tag). You can also import containers on the network from url. After the docker import url res:tag is successfully imported, you can use the docker images command to view the imported images. At this point, I believe you have a deeper understanding of "what are the management operations of Docker?" you might as well come to the actual operation! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.