In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "what are the commonly used command lines for getting started with Docker". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what command lines are commonly used for getting started with Docker.
Foreword
The Docker image consists of Dockerfile and some necessary dependencies, and the Docker container is a dynamic Docker image. To use the Docker command, you first need to know whether you are working with an image or a container. Once you know whether you are dealing with a mirror or a container, you can find the correct command.
The commonness of commands
You need to know some rules about the Docker command:
Docker CLI administrative commands start with docker, then spaces, then administrative categories, then spaces and finally commands. For example, the command docker container stop stops the container.
Commands that reference a specific container or image require the name or ID of the container or image.
For example, docker container run my_app is the command used to build and run a container named my_app. In the example in this article, I will use the name my_container to refer to the generic container. Similarly, the same is true of my_image and my_tag.
I will provide commands and generic logos separately. The sign with two dashes in front of it is the full name of the sign. The flag with a dash is the abbreviation of the full logo name. For example,-p is an abbreviation for the-- port flag.
The goal of this article is to keep these commands and tags in mind, and hopefully you can use this guide as a reference when creating containers or building images. This guide applies to Linux and Docker Engine versions 18.09.1 and API version 1.39.
Let's learn about the container command and then look at the mirror command.
Container command
Use docker container my_command
Create-create a container from the mirror
Start-start an existing container
Run-create a new container and start it
Ls-lists containers that are running
Inspect-View information about the container
Logs-print the log
Stop-gracefully stop a running container
Kill-stop the main processes in the container immediately
Rm-Delete containers that have been stopped
Mirror command
Use docker image my_command
Build-build a mirror
Push-push the mirror to the remote mirror repository
Ls-list mirrors
History-View intermediate image information
Inspect-View information about mirrors, including layers
Rm-Delete Mirror
Container & Mirror
Docker version-lists information about the Docker client and server version
Docker login-Log in to the Docker image repository
Docker system prune-removes all unused containers, networks, and unnamed images (virtual overhang)
Detailed explanation of container command
Start the container
The terms "create", "start" and "run" all have similar semantics in daily life, but each is a separate Docker command for creating and / or launching containers. Let's first look at the command to create a container.
Docker container create my_repo/my_image:my_tag-create a container from an image
I will abbreviate my_repo/my_image:my_tag to my_image below.
You can create by passing many logos.
Docker container create-a STDIN my_image
-an is an abbreviation for-attach, which refers to connecting a container to a STDIN,STDOUT or STDERR.
Now that we have created a container, let's start it.
Docker container start my_container-start an existing container
Note that the container can be referenced by the container's ID or the name of the container.
Docker container start my_container
Now that you know how to create and start a container, let's look at the most common Docker commands. It combines create and start into one command: run.
Docker container run my_image-create a new container and start it. There are also many options for this command. Let's take a look at some of them.
Docker container run-I-t-p 1000R 8000-- rm my_image
-I is an acronym for-interactive to keep STDIN open even if it is not connected;-t is an abbreviation for-tty, which allocates a pseudo terminal to connect the terminal to the container's STDIN and STDOUT.
You need to specify-I and-t to interact with the container through the terminal shell.
-p is the abbreviation of-port. A port is an interface with the outside world. 1000 8000 maps Docker port 8000 to port 1000 on the computer. If you have an app that outputs something to the browser, you can navigate the browser to localhost:1000 and view it.
-- rm automatically deletes containers that are not running.
Let's look at a few more examples of run.
Docker container run-it my_image my_command
Sh is a command that you can specify at run time. It will start a shell session inside the container and you can interact with it through the terminal. For Alpine images, sh is better than bash because Alpine images are not installed with bash. Type exit to end the interactive shell session.
Notice that we combine-I and-t into-it.
Docker container run-d my_image
-d is an acronym for-detach, which means to run the container in the background, allowing you to use the terminal for other commands while the container is running.
Check container status
If you have many running Docker containers and want to find out which one to interact with, you need to list them.
Docker container ls-lists the containers that are running and provides useful information about the containers.
Docker container ls-a-s
-an is an acronym for-- all, listing all containers (not just running containers)
-s is an abbreviation for-size, listing the size of each container.
Docker container inspect my_container-View information about the container
Docker container logs my_container-list container logs
Termination container
Sometimes you need to stop a running container, you need to use the following command:
Docker container stop my_container-gracefully stop one or more running containers. Provide a default of 10 seconds to complete any process before the container is closed.
If you think 10 seconds is too long, you can use the following command:
Docker container kill my_container-stop one or more running containers immediately. It's like unplugging the TV. In most cases, however, the stop command is recommended.
Docker container kill $(docker ps-Q)-terminates all running containers
You need to delete the container by using the following command:
Docker container rm my_container-Delete one or more containers
Docker container rm $(docker ps-a-Q)-Delete all containers that are not running
These are the key commands of the Docker container. Next, let's take a look at the commands for mirroring.
Detailed explanation of mirror command
Here are seven commands used by Docker mirroring
Build an image
Docker image build-t my_repo/my_image:my_tag. Builds a Docker image named my_image in the Dockerfile of the specified path or url.
-t is an abbreviation for tag, which tells docker to mark the image with the supplied tag, in this case, my_tag.
The full stop (.) at the end of the command Is to tell Docker to build the image based on the Dockerfile in the current working directory.
After you build the image, you want to push it to the remote repository so that it can be shared and pulled if necessary. Then the next command is very useful, although it is not a mirror command.
Docker login-Log in to the Docker image repository and type your user name and password when prompted
Docker image push my_repo/my_image:my_tag-push an image to the repository.
After you have these images, you may want to check them.
Check the mirror image
Docker image ls-list your images and the size of each image
Docker image history my_image-displays the intermediate image of the mirror, including the size and how it was created
Docker image inspect my_image-displays details about the mirror, including the layers that make up the mirror
Sometimes you need to clean up your mirror image.
Clean up the mirror
Docker image rm my_image-deletes the specified mirror. If the image is saved in the image repository, then the image is still available there.
Docker image rm $(docker images-a-Q)-removes all mirrors. This command must be used carefully. Please note that images that have been pushed to the remote repository can still be saved, which is one of the advantages of the image repository.
Thank you for your reading, the above is the content of "what is the command line commonly used for getting started with Docker"? after the study of this article, I believe you have a deeper understanding of what the command line commonly used for getting started with Docker has, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.