In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about the process of using Docker containers, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
Use of Docker containers
Docker client
The docker client is very simple, and we can enter the docker command directly to see all the command options for the Docker client.
[root@huixuan ~] # docker
Usage: docker COMMAND
A self-sufficient runtime for containers
Options:
-- config string Location of client config files (default "/ root/.docker")
-D,-- debug Enable debug mode
-- help Print usage
H,-- host list Daemon socket (s) to connect to (default [])
-l,-log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info")
-tls Use TLS; implied by-tlsverify
-- tlscacert string Trust certs signed only by this CA (default "/ root/.docker/ca.pem")
-- tlscert string Path to TLS certificate file (default "/ root/.docker/cert.pem")
-- tlskey string Path to TLS key file (default "/ root/.docker/key.pem")
-- tlsverify Use TLS and verify the remote
-v,-- version Print version information and quit
Management Commands:
Container Manage containers
Image Manage images
Network Manage networks
Node Manage Swarm nodes
Plugin Manage plugins
Secret Manage Docker secrets
Service Manage services
Stack Manage Docker stacks
Swarm Manage Swarm
System Manage Docker
Volume Manage volumes
Commands:
Attach Attach to a running container
Build Build an image from a Dockerfile
Commit Create a new image from a container's changes
Cp Copy files/folders between a container and the local filesystem
Create Create a new container
Diff Inspect changes on a container's filesystem
Events Get real time events from the server
Exec Run a command in a running container
Export Export a container's filesystem as a tar archive
History Show the history of an image
Images List images
Import Import the contents from a tarball to create a filesystem image
Info Display system-wide information
Inspect Return low-level information on Docker objects
Kill Kill one or more running containers
Load Load an image from a tar archive or STDIN
Login Log in to a Docker registry
Logout Log out from a Docker registry
Logs Fetch the logs of a container
Pause Pause all processes within one or more containers
Port List port mappings or a specific mapping for the container
Ps List containers
Pull Pull an image or a repository from a registry
Push Push an image or a repository to a registry
Rename Rename a container
Restart Restart one or more containers
Rm Remove one or more containers
Rmi Remove one or more images
Run Run a command in a new container
Save Save one or more images to a tar archive (streamed to STDOUT by default)
Search Search the Docker Hub for images
Start Start one or more stopped containers
Stats Display a live stream of container (s) resource usage statistics
Stop Stop one or more running containers
Tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
Top Display the running processes of a container
Unpause Unpause all processes within one or more containers
Update Update configuration of one or more containers
Version Show the Docker version information
Wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND-- help' for more information on a command.
[root@huixuan ~] #
You can learn more about the use of specified Docker commands by using the command docker command-- help.
For example, we want to see how the docker stats directive is used:
[root@huixuan] # docker stats-- help
Usage: docker stats [OPTIONS] [CONTAINER...]
Display a live stream of container (s) resource usage statistics
Options:
-a,-- all Show all containers (default shows just running)
-- format string Pretty-print images using a Go template
-- help Print usage
-- no-stream Disable streaming stats and only pull the first result
[root@huixuan ~] #
Run a web application
The container we ran earlier is of no particular use.
Next let's try to build a web application using docker.
We will run a Python Flask application in the docker container to run a web application.
[root@huixuan ~] # docker pull training/webapp # load image
Using default tag: latest
Trying to pull repository docker.io/training/webapp...
Latest: Pulling from docker.io/training/webapp
E190868d63f8: Pull complete
909cd34c6fd7: Pull complete
0b9bfabab7c1: Pull complete
A3ed95caeb02: Pull complete
10bbbc0fc0ff: Pull complete
Fca59b508e9f: Pull complete
E7ae2541b15b: Pull complete
9dd97ef58ce9: Pull complete
A4c1b0cb7af7: Pull complete
Digest: sha256:06e9c1983bd6d5db5fba376ccd63bfa529e8d02f23d5079b8f74a616308fb11d
Status: Downloaded newer image for docker.io/training/webapp:latest
[root@huixuan] # docker run-d-P training/webapp python app.py
E4fbb06d2dda11414252575dd77b2561b23e09c0237fac764076ba61fffa3461
[root@huixuan ~] #
Parameter description:
-d: let the container run in the background.
-P: map the network ports used inside the container to the hosts we use.
View the WEB application container
Use docker ps to see the container we are running
[root@huixuan ~] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
E4fbb06d2dda training/webapp "python app.py" 37 seconds ago Up 35 seconds 0.0.0.0 seconds ago Up 1024-> 5000/tcp kickass_wright
[root@huixuan ~] #
There is more port information here.
PORTS
0.0.0.0 1024-> 5000/tcp
Docker opens port 5000 (the default Python Flask port) to map to host port 32769.
At this time, we can access the WEB application through the browser.
We can also specify the-p flag to bind the specified port.
[root@huixuan] # docker run-d-p 5000 training/webapp python app.py
0e044f323370c157539fa9e235a37c7b2907e5920e846429562f1f18f3f6ff55
[root@huixuan ~] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0e044f323370 training/webapp "python app.py" 4 seconds ago Up 3 seconds 0.0.0.0 seconds 5000-> 5000/tcp admiring_goldwasser
E4fbb06d2dda training/webapp "python app.py" 13 minutes ago Up 13 minutes 0.0.0.0 minutes ago Up 1024-> 5000/tcp kickass_wright
[root@huixuan ~] #
Port 5000 inside the container is mapped to port 5000 on our local host.
Shortcuts to network ports
You can see the port mapping of the container through the docker ps command. Docker also provides another shortcut: docker port. You can use docker port to see the port number of a specified (ID or name) container mapped to the host.
The web application container ID we created above is: e4fbb06d2dda kickass_wright
I can use docker port e4fbb06d2dda or docker port kickass_wright to view the mapping of container ports
[root@huixuan ~] # docker port e4fbb06d2dda
5000/tcp-> 0.0.0.0 1024
[root@huixuan ~] # docker port kickass_wright
5000/tcp-> 0.0.0.0 1024
[root@huixuan ~] #
View the WEB application log
Docker logs [ID or name] can view the standard output inside the container.
[root@huixuan] # docker logs-f e4fbb06d2dda
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
172.17.8.178-[01/May/2018 01:35:36] "GET / HTTP/1.1" 200-
172.17.8.178-[01/May/2018 01:35:36] "GET / favicon.ico HTTP/1.1" 404-
-f: let dokcer logs output the standard output inside the container as if it were tail-f.
From the above, we can see that the application uses port 5000 and can see the application's access log.
View the process of the WEB application container
We can also use docker top to view the processes running inside the container
[root@huixuan ~] # docker top e4fbb06d2dda
UID PID PPID C STIME TTY TIME CMD
Root 3034 3017 0 09:32? 00:00:00 python app.py
[root@huixuan ~] #
Check the WEB application
Use docker inspect to view the underlying information of Docker. It returns a JSON file that records the configuration and status information of the Docker container.
[root@huixuan ~] # docker inspect e4fbb06d2dda
[
{
"Id": "e4fbb06d2dda11414252575dd77b2561b23e09c0237fac764076ba61fffa3461"
"Created": "2018-05-01T01:32:33.151210372Z"
"Path": "python"
"Args": [
"app.py"
]
"State": {
"Status": "running"
"Running": true
"Paused": false
"Restarting": false
"OOMKilled": false
"Dead": false
"Pid": 3034
"ExitCode": 0
"Error":
"StartedAt": "2018-05-01T01:32:35.091034063Z"
"FinishedAt": "0001-01-01T00:00:00Z"
}
....
Stop the WEB application container
[root@huixuan ~] # docker stop e4fbb06d2dda
E4fbb06d2dda
[root@huixuan ~] #
Restart the WEB application container
For containers that have been stopped, we can use the command docker start to start.
[root@huixuan ~] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0e044f323370 training/webapp "python app.py" 11 minutes ago Up 11 minutes 0.0.0.0 minutes 5000-> 5000/tcp admiring_goldwasser
[root@huixuan ~] # docker start e4fbb06d2dda
E4fbb06d2dda
[root@huixuan ~] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0e044f323370 training/webapp "python app.py" 11 minutes ago Up 11 minutes 0.0.0.0 minutes 5000-> 5000/tcp admiring_goldwasser
E4fbb06d2dda training/webapp "python app.py" 24 minutes ago Up 2 seconds 0.0.0.0 minutes ago Up 1025-> 5000/tcp kickass_wright
[root@huixuan ~] #
Docker ps-l queries the last created container:
[root@huixuan ~] # docker ps-l
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0e044f323370 training/webapp "python app.py" 11 minutes ago Up 11 minutes 0.0.0.0 minutes 5000-> 5000/tcp admiring_goldwasser
[root@huixuan ~] #
For a running container, we can restart it using the docker restart command
Remove the WEB application container
We can use the docker rm command to delete unwanted containers
When deleting a container, the container must be in a stopped state, otherwise the following error will be reported
[root@huixuan ~] # docker rm e4fbb06d2dda
Error response from daemon: You cannot remove a running container e4fbb06d2dda11414252575dd77b2561b23e09c0237fac764076ba61fffa3461. Stop the container before attempting removal or use-f
[root@huixuan ~] #
[root@huixuan ~] # docker stop e4fbb06d2dda
E4fbb06d2dda
[root@huixuan ~] # docker rm e4fbb06d2dda
E4fbb06d2dda
[root@huixuan ~] # docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0e044f323370 training/webapp "python app.py" 13 minutes ago Up 13 minutes 0.0.0.0 minutes ago Up 5000-> 5000/tcp admiring_goldwasser
[root@huixuan ~] #
After reading the above, do you have any further understanding of the process of using Docker containers? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
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.