#启动镜像
~]# 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
#提交的镜像是不能被修改的
#导入导出镜像
~]# 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
#导出镜像
~]# 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
#导入镜像
~]# 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
#没有标签
#添加标签
~]# 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/
网友评论