国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

Docker 常用命令詳細整理

2024-09-01 13:51:49
字體:
來源:轉載
供稿:網友

Docker 常用命令詳細整理

查看Docker信息(version、info)

# 查看docker版本$docker version# 顯示docker系統的信息$docker info

對image的操作(search、pull、images、rmi、history)

# 檢索image$docker search image_name# 下載image$docker pull image_name# 列出鏡像列表; -a, --all=false Show all images; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs$docker images# 刪除一個或者多個鏡像; -f, --force=false Force; --no-prune=false Do not delete untagged parents$docker rmi image_name# 顯示一個鏡像的歷史; --no-trunc=false Don't truncate output; -q, --quiet=false Only show numeric IDs$docker history image_name

啟動容器(run)

docker容器可以理解為在沙盒中運行的進程。這個沙盒包含了該進程運行所必須的資源,包括文件系統、系統類庫、shell 環境等等。但這個沙盒默認是不會運行任何程序的。你需要在沙盒中運行一個進程來啟動某一個容器。這個進程是該容器的唯一進程,所以當該進程結束的時候,容器也會完全的停止。

# 在容器中運行"echo"命令,輸出"hello word"$docker run image_name echo "hello word"# 交互式進入容器中$docker run -i -t image_name /bin/bash# 在容器中安裝新的程序$docker run image_name apt-get install -y app_name

Note: 在執行apt-get 命令的時候,要帶上-y參數。如果不指定-y參數的話,apt-get命令會進入交互模式,需要用戶輸入命令來進行確認,但在docker環境中是無法響應這種交互的。apt-get 命令執行完畢之后,容器就會停止,但對容器的改動不會丟失。

查看容器(ps)

# 列出當前所有正在運行的container$docker ps# 列出所有的container$docker ps -a# 列出最近一次啟動的container$docker ps -l

保存對容器的修改(commit)

當你對某一個容器做了修改之后(通過在容器中運行某一個命令),可以把對容器的修改保存下來,這樣下次可以從保存后的最新狀態運行該容器。

# 保存對容器的修改; -a, --author="" Author; -m, --message="" Commit message$docker commit ID new_image_name

Note: image相當于類,Container相當于實例,不過可以動態給實例安裝新軟件,然后把這個container用commit命令固化成一個image。

對容器的操作(rm、stop、start、kill、logs、diff、top、cp、restart、attach)

# 刪除所有容器$docker rm `docker ps -a -q`# 刪除單個容器; -f, --force=false; -l, --link=false Remove the specified link and not the underlying container; -v, --volumes=false Remove the volumes associated to the container$docker rm Name/ID# 停止、啟動、殺死一個容器$docker stop Name/ID$docker start Name/ID$docker kill Name/ID# 從一個容器中取日志; -f, --follow=false Follow log output; -t, --timestamps=false Show timestamps$docker logs Name/ID# 列出一個容器里面被改變的文件或者目錄,list列表會顯示出三種事件,A 增加的,D 刪除的,C 被改變的$docker diff Name/ID# 顯示一個運行的容器里面的進程信息$docker top Name/ID# 從容器里面拷貝文件/目錄到本地一個路徑$docker cp Name:/container_path to_path$docker cp ID:/container_path to_path# 重啟一個正在運行的容器; -t, --time=10 Number of seconds to try to stop for before killing the container, Default=10$docker restart Name/ID# 附加到一個運行的容器上面; --no-stdin=false Do not attach stdin; --sig-proxy=true Proxify all received signal to the process$docker attach ID

Note: attach命令允許你查看或者影響一個運行的容器。你可以在同一時間attach同一個容器。你也可以從一個容器中脫離出來,是從CTRL-C。

保存和加載鏡像(save、load)

當需要把一臺機器上的鏡像遷移到另一臺機器的時候,需要保存鏡像與加載鏡像。

# 保存鏡像到一個tar包; -o, --output="" Write to an file$docker save image_name -o file_path# 加載一個tar包格式的鏡像; -i, --input="" Read from a tar archive file$docker load -i file_path# 機器a$docker save image_name > /home/save.tar# 使用scp將save.tar拷到機器b上,然后:$docker load < /home/save.tar

登錄registry server(login)

# 登陸registry server; -e, --email="" Email; -p, --password="" Password; -u, --username="" Username$docker login

發布image(push)

# 發布docker鏡像$docker push new_image_name

根據Dockerfile 構建出一個容器

#build   --no-cache=false Do not use cache when building the image   -q, --quiet=false Suppress the verbose output generated by the containers   --rm=true Remove intermediate containers after a successful build   -t, --tag="" Repository name (and optionally a tag) to be applied to the resulting image in case of success$docker build -t image_name Dockerfile_path

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 离岛区| 阳西县| 筠连县| 临颍县| 卫辉市| 滨州市| 海林市| 鄂温| 沭阳县| 建水县| 赞皇县| 山阳县| 陕西省| 兰溪市| 探索| 抚宁县| 日照市| 怀仁县| 伽师县| 璧山县| 安达市| 壤塘县| 巴林左旗| 宾川县| 体育| 峨山| 梨树县| 蚌埠市| 嘉定区| 龙口市| 进贤县| 如东县| 勐海县| 平昌县| 濮阳市| 定州市| 东明县| 渝北区| 红安县| 漯河市| 肥乡县|