Docker容器基本操作2

#啟動(dòng)鏡像
~]# docker exec -it myalpine /bin/sh
/ # echo hello > 1.txt
/ # cat 1.txt 
hello

#提交鏡像
~]# docker commit -p myalpine lihanbing/alpine:v3.10.3_with_1.txt

#修改鏡像

/ # echo hello_world > 1.txt 
/ # cat 1.txt 
hello_world


~]# docker run -it lihanbing/alpine:v3.10.3_with_1.txt /bin/sh
/ # ls
1.txt  bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # cat 1.txt 
hello

#提交的鏡像是不能被修改的

#導(dǎo)入導(dǎo)出鏡像
~]# docker images
REPOSITORY          TAG                  IMAGE ID            CREATED             SIZE
lihanbing/alpine    v3.10.3_with_1.txt   420771180c14        7 minutes ago       5.6MB
alpine              latest               a187dde48cd2        12 days ago         5.6MB
lihanbing/alpine    v3.10.3              a187dde48cd2        12 days ago         5.6MB
hello-world         latest               fce289e99eb9        15 months ago       1.84kB

#導(dǎo)出鏡像

~]# docker save 420771180c14 > alpine:v3.10.3_with_1.txt.tar
[root@web02 ~]# ls
alpine:v3.10.3_with_1.txt.tar

#刪除鏡像
~]# docker rmi -f 420771180c14
Untagged: lihanbing/alpine:v3.10.3_with_1.txt
Deleted: sha256:420771180c145b40ade57636a8f02ae75502f58f3c379c96ae9c523d584368cc
Deleted: sha256:b3eb782b61d063124ca47a5ac7ddbf2212039760f7a3d6686fbc2ad35633e826

~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              a187dde48cd2        12 days ago         5.6MB
lihanbing/alpine    v3.10.3             a187dde48cd2        12 days ago         5.6MB
hello-world         latest              fce289e99eb9        15 months ago       1.84kB

#導(dǎo)入鏡像
~]# docker load < alpine\:v3.10.3_with_1.txt.tar 
1769289b5793: Loading layer [==================================================>]  3.584kB/3.584kB
Loaded image ID: sha256:420771180c145b40ade57636a8f02ae75502f58f3c379c96ae9c523d584368cc
[root@web02 ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
<none>              <none>              420771180c14        14 minutes ago      5.6MB
#沒(méi)有標(biāo)簽
#添加標(biāo)簽
~]# docker tag 420771180c14 lihanbing/alpine:v3.10.3_with_1.txt
[root@web02 ~]# docker images
REPOSITORY          TAG                  IMAGE ID            CREATED             SIZE
lihanbing/alpine    v3.10.3_with_1.txt   420771180c14        17 minutes ago      5.6MB

 ~]# docker run --rm -it --name myalpine_with_1.txt lihanbing/alpine:v3.10.3_with_1.txt /bin/sh
/ # ls
1.txt  bin    dev    etc    home   lib    media  mnt    opt    proc   root   run    sbin   srv    sys    tmp    usr    var
/ # cat 1.txt 
hello
#查看容器日志
~]# docker run hello-world 2>&1 >>/dev/null

~]# docker logs -f 1977140b93cb

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

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

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

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