再用一下Docker


进入docker的bash

xiaoyi@xiaoyi-Rev-1-0 ~/coding $ sudo docker run -i -t django /bin/bash
root@84447118a8af:/#
root@84447118a8af:/# ls
bin   dev  home  lib64	mnt  proc  run	 srv  tmp  var
boot  etc  lib	 media	opt  root  sbin  sys  usr
root@84447118a8af:/# exit
exit
xiaoyi@xiaoyi-Rev-1-0 ~/coding $ 

创建一个project,并启动django

xiaoyi@xiaoyi-Rev-1-0 ~/coding/fundxray $ sudo docker run -v $PWD:/usr/app -w /usr/app django python manage.py startproject test1
xiaoyi@xiaoyi-Rev-1-0 ~/github_blog/luckpiky.github.io $ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
b1057f58ce57        django              "python manage.py ..."   3 seconds ago       Up 2 seconds                            determined_knuth

xiaoyi@xiaoyi-Rev-1-0 ~/github_blog/luckpiky.github.io $ sudo docker inspect 48cdb5a0cee4

...
"IPAddress": "172.17.0.2",
...
iaoyi@xiaoyi-Rev-1-0 ~/github_blog/luckpiky.github.io $ ping 172.17.0.2
PING 172.17.0.2 (172.17.0.2) 56(84) bytes of data.
64 bytes from 172.17.0.2: icmp_seq=1 ttl=64 time=0.157 ms


保存容器中修改的内容到新的镜像中

以下是windows上跑的docker:
PS C:/Users/Administrator> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
centos_dev                 latest              9e74d525d304        11 hours ago        387MB
ubuntu                     latest              c9d990395902        9 days ago          113MB
centos                     latest              e934aafc2206        2 weeks ago         199MB
docker4w/nsenter-dockerd   latest              cae870735e91        5 months ago        187kB
PS C:/Users/Administrator> docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
e4c97441ceb1        centos_dev          "/bin/bash"         11 minutes ago      Up 11 minutes                           relaxed_ride
PS C:/Users/Administrator> docker  commit e4c97441ceb1 "dev2"
sha256:50450538bc3948a81f5f947f285ecafd7430de9d3b76e22ae8a43c1eed0ab397
PS C:/Users/Administrator>
PS C:/Users/Administrator> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE
dev2                       latest              50450538bc39        6 seconds ago       387MB
centos_dev                 latest              9e74d525d304        11 hours ago        387MB
ubuntu                     latest              c9d990395902        9 days ago          113MB
centos                     latest              e934aafc2206        2 weeks ago         199MB
docker4w/nsenter-dockerd   latest              cae870735e91        5 months ago        187kB
PS C:/Users/Administrator>

保存后的镜像,使用docker -i -t xxx启动后,原先设置的环境都还存在,比如之前制定的文件夹映射等。

删除镜像

PS C:/Users/Administrator> docker rmi dev2
Untagged: dev2:latest
Deleted: sha256:50450538bc3948a81f5f947f285ecafd7430de9d3b76e22ae8a43c1eed0ab397
PS C:/Users/Administrator>

这里删除时,如果镜像曾经运行过,会删除失败,网上找到的说要用docker rm XXX删除对应的容器id(可以使用docker ps -L来查看之前运行过的容器记录),删除容器引用后,确实能够删除镜像了,但是多删除了一个其他镜像的引用,结果该镜像就无法运行了,不知道什么原因。

原创文章,作者:3628473679,如若转载,请注明出处:https://blog.ytso.com/244479.html

(0)
上一篇 2022年4月17日
下一篇 2022年4月17日

相关推荐

发表回复

登录后才能评论