ICode9

精准搜索请尝试: 精确搜索
首页 > 互联网> 文章详细

再用一下Docker

2018-09-29 11:02:06  阅读:185  来源: 互联网

标签:


进入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来查看之前运行过的容器记录),删除容器引用后,确实能够删除镜像了,但是多删除了一个其他镜像的引用,结果该镜像就无法运行了,不知道什么原因。

标签:
来源: https://luckpiky.github.io/docker2/#

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有