- docker 服務重啟,關(guān)閉仍稀,啟動及版本查看
[root@localhost /]# systemctl restart docker.service #重啟服務
[root@localhost /]# systemctl stop docker.service #關(guān)閉服務
[root@localhost /]# systemctl start docker.service #啟動服務
[root@iZm5e3hwzuo58e05kxjiifZ /]# docker -v #docker版本查看
[root@localhost /]# docker search centos|head -3 #搜索鏡像
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 4754 [OK]
[root@localhost /]# docker pull centos #下載鏡像
Using default tag: latest.............
Digest: sha256:6f6d986d425aeabdc3a02cb61c02abb2e78e57357e92417d6d58332856024faf
Status: Downloaded newer image for centos:latest
[root@localhost /]# docker images #查看鏡像
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5182e96772bf 7 weeks ago 200MB
- docker 創(chuàng)建一個容器(前臺/后臺并指定映射目錄和端口)
-i:允許我們對容器內(nèi)的 (STDIN) 進行交互
-t:在新容器內(nèi)指定一個偽終端或終端
-v:是掛在宿機目錄昧甘, /docker_test是宿機目錄鳄乏,/yufei是當前docker容器的目錄瞳浦,宿機目錄必須是絕對的盖文。
--name:是給容器起一個名字,可省略双饥,省略的話docker會隨機產(chǎn)生一個名字
-P 指定映射的端口
--net #指定網(wǎng)絡
--link 鏈接到另一個容器
--------------------------------------------------------------------------------------------------
docker run -it -v /test:/test --name centos /bin/bash #創(chuàng)建容器并進入(交互模式退出會后容器會自動關(guān)閉)
docker run -d -v /test:/test centos tail -f /dev/null #創(chuàng)建容器并放入后臺運行(退出容器不會關(guān)閉)
docker run -dit -v /test:/test centos /bin/bash #創(chuàng)建容器并放入后臺運行(進入后臺和tty模式媒抠,退出容器不會關(guān)閉)
docker run -d -v /test:/test -P 80:80 nginx:latest
#后臺啟動并運名為nginx的容器,然后將容器的80端口映射到物理機的80端口.
[root@iZm5e3hwzuo58e05kxjiifZ rc.d]# docker ps -a #查看所有創(chuàng)建的容器包括已經(jīng)停止的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70e151cd2766 centos "/bin/bash" 7 seconds ago Exited (0) 5 seconds ago zealous_mclean
dfdf33852d47 centos "/bin/bash" 20 seconds ago Up 19 seconds frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ rc.d]# docker ps #查看所有運行的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfdf33852d47 centos "/bin/bash" 22 seconds ago Up 21 seconds frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ rc.d]# docker ps -l #查看最新創(chuàng)建的容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
70e151cd2766 centos "/bin/bash" 29 minutes ago Exited (0) 29 minutes ago
- docker 利用已存在的容器創(chuàng)建一個鏡像(Dockerfile構(gòu)建鏡像略)
-a #提交的鏡像作者
-c #使用Dockerfile指令來創(chuàng)建鏡像
-m #提交時附上說明文字
-p #在commit時兢哭,將容器暫停
-------------------------------------------------------------------------------------------
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker commit -a "王云龍" -m "創(chuàng)建的新鏡像" redis wyl5588redis-test
sha256:9c2d2fc6e09cb35543fbb2467db90e741dc6b7daabab83924534bcfe6641bbe2
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
wyl5588redis-test latest 9c2d2fc6e09c 3 seconds ago 83.4MB
[root@iZm5e3hwzuo58e05kxjiifZ Dockerfile]# docker tag centos 192.168.8.88:5000/centos:v1.0 #給centos鏡像打一個行的tag
[root@iZm5e3hwzuo58e05kxjiifZ Dockerfile]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
192.168.8.88:5000/centos v1.0 5182e96772bf 7 weeks ago 200MB
centos latest 5182e96772bf 7 weeks ago 200MB
[root@iZm5e3hwzuo58e05kxjiifZ Dockerfile]#docker push 192.168.8.88:5000/centos:v1.0 #將本地docker中的鏡像推送到鏡像倉庫中
docker save 5588/mongo3.2 5588/redis 5588/nginx 5588/qiantai >Qiantai_images.tar #鏡像導出
docker load </Docker_Images/Qiantai.images.tar #鏡像導入
docker rmi centos #刪除centos鏡像
docker rmi -f centos #強制刪除
docker images -q #獲取進行的ID
docker rmi -f $(docker images -q)#刪除全部鏡像
[root@iZm5e3hwzuo58e05kxjiifZ ~]# touch admin
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker cp ./admin nginx:/tmp/
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker exec -it nginx /bin/bash
root@aaefa2aebc8b:/# ls /tmp
admin
root@aaefa2aebc8b:/# touch /tmp/wyltest
exit
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker cp -a nginx:/tmp/wyltest ./
Error: No such container:path: nginx:/tmp/*
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker cp -a nginx:/tmp/admin ./
[root@iZm5e3hwzuo58e05kxjiifZ rc.d]# docker inspect frosty_saha #查看容器詳情如ip等frosty_saha為容器別名
[
{
"Id": "dfdf33852d470d0cd8e70a4b9aad36a00585579952834471159100aacea885d9",
"Created": "2018-09-28T04:44:11.394993867Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",....
)]
- docker 關(guān)閉冲秽,啟動,重啟矩父,刪除容器
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker start frosty_saha #啟動容器
frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker stop frosty_saha #關(guān)閉容器
frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker restart frosty_saha #重啟容器
frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfdf33852d47 centos "/bin/bash" 41 minutes ago Up 13 seconds frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker rm -f frosty_saha #強制刪除容器
frosty_saha
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker rm -f $(docker ps -qa) #強制刪除所有容器
70e151cd2766
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aaefa2aebc8b 5588/nginx "nginx -g 'daemon of…" 51 seconds ago Up 51 seconds 0.0.0.0:80->80/tcp nginx
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker exec -it nginx /bin/bash #進入某一容器
root@aaefa2aebc8b:/#
- docker 容器外創(chuàng)建一個后臺任務
[root@izm5e3hwzuo58e05kxjiifz ~]# docker exec -d qiantai python /mnt/log/tbxScripts.py
- docker 查看某一容器的 進程锉桑,日志,端口
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker top nginx #查看nginx容器進程
UID PID PPID C STIME TTY TIME CMD
root 2018 1984 0 13:35 ? 00:00:00 nginx: master process nginx -g daemon off;
101 2094 2018 0 13:35 ? 00:00:00 nginx: worker process
101 2095 2018 0 13:35 ? 00:00:00 nginx: worker process
101 2096 2018 0 13:35 ? 00:00:00 nginx: worker process
101 2097 2018 0 13:35 ? 00:00:00 nginx: worker process
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker logs -tf nginx #查看容器日志
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker port nginx #查看容器映射的端口
80/tcp -> 0.0.0.0:80
[root@iZm5e3hwzuo58e05kxjiifZ ~]# docker stats 容器監(jiān)控
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
aaefa2aebc8b nginx 0.00% 3.145MiB / 15.51GiB 0.02% 17.7kB / 233kB 0B / 0B 5
da5fc7ab052c qiantai 0.78% 1.909GiB / 15.51GiB 12.31% 327MB / 367kB 0B / 8.19kB 11
f4ce4818308c mongodb3.2 0.03% 616MiB / 15.51GiB 3.88% 364kB / 327MB 0B / 1.05MB 24
eb841f913814 redis 0.00% 6.312MiB / 15.51GiB 0.04% 2.78kB / 1.86kB