第三節(jié)、Docker的基本操作命令

查詢所有容器的ID(包括已停止的)docker ps -a -q
刪除所有容器docker rm $(docker ps -a -q)
國外DockerHub官方鏡像倉庫網(wǎng)址https://hub.docker.com/
官方鏡像列表https://hub.docker.com/explore
國內(nèi)網(wǎng)易云鏡像網(wǎng)址http://hub-mirror.c.163.com

[root@localhost default]# vim /etc/docker/daemon.json
{
        "registry-mirrors": [ "http://hub-mirror.c.163.com" ]
}

也可以替換Docker官方國內(nèi)鏡像源https://registry.docker-cn.com
備注:daemon.json文件有誤會導(dǎo)致docker服務(wù)無法啟動,報錯如下

[root@localhost default]# systemctl restart docker
Job for docker.service failed because the control process exited with error code. See "systemctl status docker.service" and "journalctl -xe" for details.
[root@localhost default]# systemctl status docker.service
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
   Active: failed (Result: start-limit) since Tue 2018-09-18 02:28:53 CST; 32s ago
     Docs: https://docs.docker.com
  Process: 21572 ExecStart=/usr/bin/dockerd (code=exited, status=1/FAILURE)
 Main PID: 21572 (code=exited, status=1/FAILURE)

Sep 18 02:28:52 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Sep 18 02:28:52 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Sep 18 02:28:52 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Sep 18 02:28:52 localhost.localdomain systemd[1]: docker.service failed.
Sep 18 02:28:53 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.
Sep 18 02:28:53 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service
Sep 18 02:28:53 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
Sep 18 02:28:53 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Sep 18 02:28:53 localhost.localdomain systemd[1]: docker.service failed.
[root@localhost default]# journalctl -xe
Sep 18 02:28:52 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.
Sep 18 02:28:52 localhost.localdomain systemd[1]: Starting Docker Application Container Engine...
-- Subject: Unit docker.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.service has begun starting up.
Sep 18 02:28:52 localhost.localdomain dockerd[21572]: unable to configure the Docker daemon with file /etc/docker/daemon.json: invalid character 
Sep 18 02:28:52 localhost.localdomain systemd[1]: docker.service: main process exited, code=exited, status=1/FAILURE
Sep 18 02:28:52 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.service has failed.
-- 
-- The result is failed.
Sep 18 02:28:52 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Sep 18 02:28:52 localhost.localdomain systemd[1]: docker.service failed.
Sep 18 02:28:53 localhost.localdomain systemd[1]: docker.service holdoff time over, scheduling restart.
Sep 18 02:28:53 localhost.localdomain systemd[1]: start request repeated too quickly for docker.service
Sep 18 02:28:53 localhost.localdomain systemd[1]: Failed to start Docker Application Container Engine.
-- Subject: Unit docker.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit docker.service has failed.
-- 
-- The result is failed.
Sep 18 02:28:53 localhost.localdomain systemd[1]: Unit docker.service entered failed state.
Sep 18 02:28:53 localhost.localdomain systemd[1]: docker.service failed.

Docker鏡像images存放目錄/var/lib/docker/image
Docker鏡像數(shù)據(jù)卷管理目錄/var/lib/docker/volumes
容器是以鏡像為基礎(chǔ)運(yùn)行的因此要刪除鏡像需要優(yōu)先刪除與之關(guān)聯(lián)的所有容器
查看images鏡像docker images
刪除images鏡像(根據(jù)上一步查詢的ID)docker rmi image_id

[root@localhost docker]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              4ab4c602aa5e        9 days ago          1.84kB
nginx               latest              06144b287844        12 days ago         109MB
[root@localhost docker]# docker rmi 4ab4c602aa5e 
Untagged: hello-world:latest
Untagged: hello-world@sha256:0add3ace90ecb4adbf7777e9aacf18357296e799f81cabc9fde470971e499788
Deleted: sha256:4ab4c602aa5eed5528a6620ff18a1dc4faef0e1ab3a5eddeddb410714478c67f
Deleted: sha256:428c97da766c4c13b19088a471de6b622b038f3ae8efa10ec5a37d6d31a2df0b

備注:拉取pull公共鏡像倉庫已存在文件不需要登錄,但是如果是不存在的鏡像會報錯提示倉庫未創(chuàng)建或提示你登錄,登錄指令docker login
下面是拉取hello-world鏡像時輸入錯誤提示的報錯信息

[root@localhost docker]# docker pull hell-world
Using default tag: latest
Error response from daemon: pull access denied for hell-world, repository does not exist or may require 'docker login'
[root@localhost docker]# docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: sa125417
Password: 
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
[root@localhost docker]# docker logout
Removing login credentials for https://index.docker.io/v1/

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Docker — 云時代的程序分發(fā)方式 要說最近一年云計算業(yè)界有什么大事件?Google Compute Engi...
    ahohoho閱讀 15,872評論 15 147
  • 0x01 核心概念 Docker鏡像類似于虛擬機(jī)鏡像,可以理解為一個面向Docker引擎的只讀模板,包含了文件系統(tǒng)...
    閑云逸心閱讀 4,977評論 0 9
  • 《Docker從入門到實踐》閱讀筆記 原書地址: https://yeasy.gitbooks.io/docker...
    GuoYuebo閱讀 11,670評論 1 39
  • 體驗入:1、今天給斯比特大哥家田哥滴滴打車,司機(jī)就在附近卻找不到位置,我說加司機(jī)微信給發(fā)個位置,司機(jī)說不用了你重新...
    京心達(dá)孫艷利閱讀 149評論 0 0
  • 近期常向親朋好友們念叨所用手機(jī)的好,聽到他們討論手機(jī)話題,便情不自禁地夸贊一番,“別說,這手機(jī)買的太值了,用了兩年...
    肆方閱讀 164評論 0 0

友情鏈接更多精彩內(nèi)容