In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Before we begin
The official account has previously published three articles about Docker images and repositories. If you need to read them, you can reply to the image on Wechat [official account] to get links to the articles. Next, let's create the first docker container.
This article uses two examples to explain docker commonly used commands, including run, ps, stop, start, rm, inspect, logs, exec and other sub-commands, these basic commands are used relatively frequently, it is recommended to master the use method.
Take a chestnut.
Create a nginx container and mount the host "/ tmp/demo" directory to the container "/ demo" directory.
Create a container
Docker run-- name test-d-p 80:80-v / tmp/demo:/usr/share/nginx/html nginxe112ef640768f53ee32ae622874e51c79545e2e9ce02066f091190f2b67643fa
List containers
Docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESe112ef640768 nginx "nginx-g'daemon of..." 6 seconds ago Up 4 seconds 0.0.0.0 daemon of 80-> 80/tcp test
Create a file in the host
Echo 'hello docking' > / tmp/demo/index.html
Read a file in a container
Docker exec-ti test cat / usr/share/nginx/html/index.htmlhello docker! Mount directory permissions
If you want the container to only read but not write, mount the host directory with read-only permissions.
Close the container
Docker stop testtest# launch Container # docker start test
Delete Container
Docker rm test test
Be careful。 Only the container itself is deleted, and the mounted directory and its data are not deleted.
Create a new container
Docker run-- name new-d-p 80:80-v / tmp/demo:/usr/share/nginx/html:ro nginx
Note: ro indicates read-only permission, and the default value rw indicates read-write permission.
Log in to the container console
Docker exec-ti new / bin/bashroot@71a8e8ac3104:/#
Try to delete a file within the container
Root@71a8e8ac3104:/# rm / usr/share/nginx/html/index.html rm: cannot remove'/ usr/share/nginx/html/index.html': Read-only file system
Exit the Container console
Root@71a8e8ac3104:/# exit accesses this container
The nginx container is created and, of course, accessible.
Get the container IP
Docker inspect new | grep-I 'IPAddress' "SecondaryIPAddresses": null, "IPAddress": "172.17.0.2", "IPAddress": "172.17.0.2"
The curl command returns exactly the index.html created on the host.
Curl http://172.17.0.2hello docker!
Container log-stdout standard output
Docker logs test172.17.0.1-- [27/Mar/2016:09:33:15 + 0000] "GET / HTTP/1.1" 20014 "-" curl/7.47.0 "-" Command help
The following are the commands used in the article.
Docker run-helpUsage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Run a command in a new containerOptions:-name string Assign a name to the container-d,-- detach Run container in background and print container ID-v,-- volume list Bind mount a volume-t,-- tty Allocate a pseudo-TTY-i,-- interactive Keep STDIN open even if not attached
Reference article
Create a docker container
Doker&k8s Qun [703906133]
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.