Docker 容器基礎操作
初次啟動 Docker 容器命令
docker run -d(后臺運行容器) -p 8080:8080(系結埠) xiaopang/centos-nodejs-1
解釋:
通過docker run 首先從本地查詢是否有這個鏡像,如果有直接啟動本鏡像,如果沒有鏡像,直接從官方鏡像下載鏡像,并啟動容器
啟動已停止的Docker 容器命令
docker start eab4ad610972(容器ID)
查看正在運行的Docker容器
docker ps
查看所有的停止或正在運行的容器
docker ps -a
停止Docker 容器
docker stop eab4ad610972(容器ID)
查看Docker 容器運行的日志
docker logs -f eab4ad610972(容器ID)
洗掉已停止的Docker 容器
docker rm eab4ad610972(容器ID)
登錄容器(類似ssh)
docker exec -it eab4ad610972(容器ID) bash(執行的命令)
掛載帶有資料卷的容器
docker run -p 8080:8080 -d --mount source=my-vol,target=/webapp centos-nodejs:1.0
[root@localhost ~]# docker run -p 8080:8080 -d --mount source=my-vol,target=/webapp centos-nodejs:1.0
5f73feb5e99a215255d0b95bce5cb5ef08549c5121af11afce63a4618acadce3
查看容器的掛載資訊
docker inspect 5f73feb5e99a
"Mounts": [
{
"Type": "volume",
"Source": "my-vol",
"Target": "/webapp"
}
],
洗掉一個不在使用的資料卷
docker volume rm my-vol
[root@localhost ~]# docker volume rm my-vol
Error response from daemon: remove my-vol: volume is in use - [5f73feb5e99a215255d0b95bce5cb5ef08549c5121af11afce63a4618acadce3]
清理所有沒有占用的資料卷
docker volume prune
[root@localhost ~]# docker volume prune
WARNING! This will remove all local volumes not used by at least one container.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
Docker 倉庫
公有倉庫
Docker hub 注冊
Docker hub 注冊地址:https://hub.docker.com/
搜索鏡像
docker search centos
拉取鏡像
docker pull centos
登錄公有倉庫
docker login
推送鏡像到共有倉庫
- 給你的鏡像打標簽
docker tag centos-nodejs:1.0 xiaohai0407/centos-nodejs:1.0
- 查看打好標簽的本地鏡像
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nodejs 1.0 88fbf99d311d 3 minutes ago 343MB
xiaohai0407/centos-nodejs 1.0 88fbf99d311d 3 minutes ago 343MB
centos latest 5182e96772bf 8 days ago 200MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
- 上傳鏡像到docker 官方鏡像庫
docker push xiaohai0407/centos-nodejs
[root@localhost first]# docker push xiaohai0407/centos-nodejs
The push refers to repository [docker.io/xiaohai0407/centos-nodejs]
c1f3e6373b76: Pushed
bdba1884d9f2: Pushed
a37663980625: Pushed
2efbd85d8018: Pushed
1d31b5806ba4: Mounted from library/centos
1.0: digest: sha256:9c0fef1f79934c6a102437b3e0c6da61e48be61a0ce6f0d11cc157fb1a53704b size: 1362
- 查看上傳鏡像是否成功
[root@localhost first]# docker search xiaohai0407
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
xiaohai0407/centos-nodejs base of centos 7 ,create nodejs hello word 0
私有倉庫
安裝私有倉庫
docker run -d -p 5000:5000 -v /opt/data/registry:/var/lib/registry registry
[root@localhost ~]# docker run -d \
> -p 5000:5000 \
> -v /opt/data/registry:/var/lib/registry \
> registry
Unable to find image 'registry:latest' locally
latest: Pulling from library/registry
4064ffdc82fe: Pull complete
c12c92d1c5a2: Pull complete
4fbc9b6835cc: Pull complete
765973b0f65f: Pull complete
3968771a7c3a: Pull complete
Digest: sha256:20bbbc0f6384cf7dc6e292ccbe75935b73c92ec776543c970904bc60feceb129
Status: Downloaded newer image for registry:latest
36d7fb0a86534d32eb7f5c4090ebb5db35e801822433fb8138bf94db55477240
將私有倉庫的存盤路徑通過-v 引數設定
到/opt/data/registry路徑下
上傳鏡像到私有倉庫
標記鏡像到私有倉庫
docker tag ubuntu:latest 127.0.0.1:5000/centos-nodejs:1.0
上傳鏡像到私有倉庫
docker push 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker push 127.0.0.1:5000/centos-nodejs:1.0
The push refers to repository [127.0.0.1:5000/centos-nodejs]
268a067217b5: Pushed
c01d74f99de4: Pushed
ccd4d61916aa: Pushed
8f2b771487e9: Pushed
f49017d4d5ce: Pushed
1.0: digest: sha256:958eaeb7e33e6c4f68f7fef69b35ca178c7f5fb0dd40db7b44a8b9eb692b9bc5 size: 1357
查看倉庫中已經上傳的鏡像
curl 127.0.0.1:5000/v2/_catalog
[root@localhost registry]# curl 127.0.0.1:5000/v2/_catalog
{"repositories":["centos-nodejs"]}
倉庫中已經包含了centos-nodejs這個tag的鏡像檔案
洗掉本地鏡像
docker image rm 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
xiaohai0407/centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
centos latest 5182e96772bf 9 days ago 200MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
registry latest b2b03e9146e1 5 weeks ago 33.3MB
[root@localhost registry]#
從本地倉庫下載鏡像
docker pull 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker pull 127.0.0.1:5000/centos-nodejs:1.0
1.0: Pulling from centos-nodejs
Digest: sha256:958eaeb7e33e6c4f68f7fef69b35ca178c7f5fb0dd40db7b44a8b9eb692b9bc5
Status: Downloaded newer image for 127.0.0.1:5000/centos-nodejs:1.0
[root@localhost registry]# docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
xiaohai0407/centos-nodejs 1.0 88fbf99d311d 24 hours ago 343MB
centos latest 5182e96772bf 9 days ago 200MB
127.0.0.1:5000/centos-nodejs 1.0 735f80812f90 2 weeks ago 83.5MB
ubuntu latest 735f80812f90 2 weeks ago 83.5MB
registry latest b2b03e9146e1 5 weeks ago 33.3MB
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/33951.html
標籤:其他
