国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

Docker常用命令

2023-04-14 17:24:32 7765

Docker常用命令

幫助命令

docker indo #顯示docker系統(tǒng)信息,包括鏡像和容器的數(shù)量
docker
--help #docker的版本信息
docker version
#docker幫助命令

幫助文檔地址:

鏡像命令

docker images 查看所有本地主機(jī)上的鏡像

[16:24:31 root@hwcentos7 ~]#docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
hello-world   latest   feb5d9fea6a5  
18 months ago   13.3kB

#解釋?zhuān)?/span>
REPOSITORY
鏡像的倉(cāng)庫(kù)源
TAG 鏡像的標(biāo)簽
IMAGE ID 鏡像ID
CREATED 鏡像的創(chuàng)建時(shí)間
SIZE 鏡像的大小

#可選項(xiàng)
 
-a, --all             Show all images (default hides intermediate images)
 
-q, --quiet           Only show image IDs 只顯示ID

docker search 搜索鏡像

[16:35:00 root@hwcentos7 ~]#docker search mysql
NAME                           DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                           MySQL is a widely used, open-source relation…  
13980     [OK]
mariadb                         MariaDB Server is a high performing open sou…  
5329     [OK]

#可選項(xiàng)

docker pull 下載鏡像

#可選項(xiàng)
 
-a, --all-tags               Download all tagged images in the repository
     
--disable-content-trust   Skip image verification (default true)
     
--platform string         Set platform if server is multi-platform capable
 
-q, --quiet                   Suppress verbose output

docker pull mysql[:tags]
#不指定版本 默認(rèn)下載最新的
[16:37:33 root@hwcentos7 ~]
#docker pull mysql
Using default tag: latest
latest: Pulling from library/mysql
72a69066d2fe: Pull complete
#分層級(jí)下載
93619dbc5b36: Pull complete
99da31dd6142: Pull complete
626033c43d70: Pull complete
37d5d7efb64e: Pull complete
ac563158d721: Pull complete
d2ba16033dad: Pull complete
688ba7d5c01a: Pull complete
00e060b6d11d: Pull complete
1c04857f594f: Pull complete
4d7cfa90e6ea: Pull complete
e0431212d27d: Pull complete
Digest: sha256:e9027fe4d91c0153429607251656806cc784e914937271037f7738bd5b8e7709
#防偽標(biāo)識(shí)
Status: Downloaded newer image
for mysql:latest
docker.io/library/mysql:latest
#真實(shí)目錄

#指定版本下載
[16:44:25 root@hwcentos7 ~]
#docker pull mysql:5.7
5.7: Pulling from library/mysql
72a69066d2fe: Already exists
#已存在的層級(jí)不用重新下載
93619dbc5b36: Already exists
99da31dd6142: Already exists
626033c43d70: Already exists
37d5d7efb64e: Already exists
ac563158d721: Already exists
d2ba16033dad: Already exists
0ceb82207cd7: Pull complete
37f2405cae96: Pull complete
e2482e017e53: Pull complete
70deed891d42: Pull complete
Digest: sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Status: Downloaded newer image
for mysql:5.7
docker.io/library/mysql:5.7

[16:47:59 root@hwcentos7 ~]
#docker images
REPOSITORY   TAG       IMAGE ID       CREATED         SIZE
mysql        
5.7       c20987f18b13   15 months ago   448MB
mysql         latest   3218b38490ce  
15 months ago   516MB
hello-world   latest   feb5d9fea6a5  
18 months ago   13.3kB

docker rmi 刪除鏡像

[16:48:44 root@hwcentos7 ~]#docker rmi -f c20987f18b13
Untagged: mysql:5.7
Untagged: mysql@sha256:f2ad209efe9c67104167fc609cca6973c8422939491c9345270175a300419f94
Deleted: sha256:c20987f18b130f9d144c9828df630417e2a9523148930dc3963e9d0dab302a76
Deleted: sha256:6567396b065ee734fb2dbb80c8923324a778426dfd01969f091f1ab2d52c7989
Deleted: sha256:0910f12649d514b471f1583a16f672ab67e3d29d9833a15dc2df50dd5536e40f
Deleted: sha256:6682af2fb40555c448b84711c7302d0f86fc716bbe9c7dc7dbd739ef9d757150
Deleted: sha256:5c062c3ac20f576d24454e74781511a5f96739f289edaadf2de934d06e910b92

docker rmi
-f $(docker images -aq) #刪除全部鏡像

容器命令

有了鏡像才可以使用容器

docker安裝一個(gè)centos學(xué)習(xí)

docker pull centos

新建容器并啟動(dòng)

docker run [可選參數(shù)] image

#可選參數(shù)
--name="Name" 指定容器名字
-d 后臺(tái)運(yùn)行
-it 使用交互方式運(yùn)行
-p 指定容器的端口 -p 8080:8080
-p 主機(jī)端口:容器端口 主機(jī)和容器端口的映射
-p ip主機(jī)端口:容器端口
-P 隨機(jī)指定端口

#測(cè)試

列出所有運(yùn)行的容器

docker ps 命令
#列出當(dāng)前正在運(yùn)行的容器
-a #列出所有的容器,包括歷史的
-n=? #列出最近使用的幾個(gè)容器
-q #只顯示容器ID

[09:48:21 root@hwcentos7 ~]
#docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS   PORTS     NAMES
[09:48:38 root@hwcentos7 ~]
#docker ps -a
CONTAINER ID   IMAGE         COMMAND       CREATED             STATUS                     PORTS     NAMES
8b564e71aa56   centos        
"/bin/bash"   About a minute ago   Exited (0) 19 seconds ago             jolly_tharp
6d9203bc679f   feb5d9fea6a5  
"/hello"      18 hours ago         Exited (0) 18 hours ago               agitated_babbage

退出容器

exit 退出容器并停止

ctrl+p+q 退出容器不停止

刪除容器

docker rm #不能刪除正在運(yùn)行的 -f可強(qiáng)制刪除
docker
rm -f $(docker ps -aq)

啟動(dòng)和停止容器

docker start 容器ID #啟動(dòng)容器
docker restart 容器ID #重啟容器
docker stop 容器ID #停止正在運(yùn)行的容器
docker kill 容器ID #強(qiáng)制停止

常用其他命令

查看日志

docker logs

-tf  #顯示日志
--tail number #顯示日志條數(shù)

查看容器中的進(jìn)程

docker top 容器ID

查看鏡像的元數(shù)據(jù)

docker inspect 容器ID

進(jìn)入當(dāng)前正在運(yùn)行的容器

#方式一 進(jìn)入容器后打開(kāi)新的終端
docker exec
-it 容器ID /bin/bash
#方式二 正在執(zhí)行當(dāng)前的代碼 沒(méi)有打開(kāi)新的終端
docker attach
容器ID

從容器內(nèi)拷貝文件到主機(jī)

docker cp 容器ID:容器內(nèi)文件路徑 目的主機(jī)路徑

docker volume 查看所有卷的情況

所有的docker容器內(nèi)的卷,都在/var/lib/docker/volumes/下

 


提交成功!非常感謝您的反饋,我們會(huì)繼續(xù)努力做到更好!

這條文檔是否有幫助解決問(wèn)題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進(jìn)一步的反饋信息:

在文檔使用中是否遇到以下問(wèn)題: