如何删除docker images 导出/containers

Understand images & containers of Docker - 简书
Understand images & containers of Docker
在使用 Docker 之前我们通常会使用
来 build & share 开发环境。每个 Vagrant package 都是一个完整的虚拟主机,一个 package 通常有几个 G。共享和更新几个 G 的 package 是很一件昂贵的事情。
在 Docker 世界中将 Vagrant 中的 package 拆成 containers & images,这两个概念支撑这整个 Docker 世界。
container:一个剥掉壳的最小化 Linux。
image:一个 software,它将会被加载到container中。
当运行 docker run helloworld 时,docker 会做如下三件事情:
在本地查找 hello-world software image
如果找不到,从 Docker Hub 上下载 image
将 image 加载到 container 中并 run
通常我们使用 docker-machine 管理 container,使用 docker 来运行image。images 通过
的使用者,你将会很轻松的上手 Docker Hub。关于 Docker Hub 本文暂不做介绍)
Docker 中的 container 在哪?
container 是一个剥了壳的,最基础的 Linux。在 Mac OS 中我们使用 docker-machine 来管理 container。
创建 container
创建一个名为 dev 的 container : docker-machine create --driver virtualbox dev
查看本地的 containers
mydockerbuild
docker-machine ls
virtualbox
tcp://192.168.99.101:2376
virtualbox
tcp://192.168.99.100:2376
查看 container 状态
mydockerbuild
docker-machine active
mydockerbuild
docker-machine status dev
连接到 container
mydockerbuild
docker-machine ssh dev
## ## ## ## ##
/"""""""""""""""""\___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~~ ~ /
\____\_______/
___ | |_|___ \ __| | ___
___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
Boot2Docker version 1.8.2, build master : aba6192 - Thu Sep 10 20:58:17 UTC 2015
Docker version 1.8.2, build 0a8c2e3
er@dev:~$ uname -a
Linux dev 4.0.9-boot2docker #1 SMP Thu Sep 10 20:39:20 UTC
Docker 中的 image 是什么?
docker run helloworld 运行一个image
此时 docker 正在 run 一个名为 hello-world 的应用程序,它将会打印如下结果:
docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
e8ad: Pull complete
af: Pull complete
Digest: sha256:a68868bfe696cf5ca39e3e31b79c1e50feaee4ce5e28df2f051d5c
Status: Downloaded newer image for hello-world:latest
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.
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:
此时的 hello-world 程序在 docker 中成为一个 image,它被 docker 放在 container 上面运行。
docker images 查看本地的 images
mydockerbuild
docker images
REPOSITORY
VIRTUAL SIZE
docker-whale
5 hours ago
91e54dfb1179
6 weeks ago
hello-world
8 weeks ago
docker/whalesay
4 months ago
images & containers 是 Docker 世界中最基本的概念。image 即 software,container 即运行 software 用的操作系统。在 Docker 世界中,我们大部分时间都在和 Docker 中的 images 打交道。docker 采用类似 git 的机制来管理和分享 images,当我们使用 docker 创建分享 images 时,如同使用 git 一样。Docker Hub 的存在,如同 Github 对 git 的存在一样,让 docker images 分享变得非常容易。
full-stack web & iOS developer.
working at tho...Removing Docker Containers and Images - 推酷
Removing Docker Containers and Images
Removing Docker Containers and Images
In a recent post aboutDocker, we looked into some things that differentiate Docker containers from Virtual Machines. I also gave a brief example of creating your first Docker image. If any of that piqued your interest and you started just trying stuff, you end up like I did with a BUNCH of images now cluttering up your machine and wondering how in the world can I clean this up? Here are a few commands that will get your Docker environment under control.
List Docker Images
docker images
Docker provides a number of simple options to allow the admin to manage the environment. Docker images for examples lets us see all the docker images on the machine.
Last login: Fri Apr 14 17:16:30 on ttys001
Danny: & docker images
REPOSITORY&&&&&&&&&&TAG&&&&&&&&&&&&&&&&IMAGE ID&&&&&&&&&&&&CREATED&&&&&&&&&&&&SIZE
oraclelinux&&&&&&&&latest&&&&&&&&&&&&&&62e&&&&&&&&2 days ago&&&&&&&&&&225 MB
pythonslim&&&&&&&&&&latest&&&&&&&&&&&&&&2f61057fee22&&&&&&&&3 weeks ago&&&&&&&&318 MB
&none&&&&&&&&&&&&&&&&none&&&&&&&&&&&&&&&c133f715830e&&&&&&&&3 weeks ago&&&&&&&&310 MB
sqlslim&&&&&&&&&&&&latest&&&&&&&&&&&&&&6cab4fd15c1d&&&&&&&&3 weeks ago&&&&&&&&348 MB
oels&&&&&&&&&&&&&&&&latest&&&&&&&&&&&&&&f7&&&&&&&&3 weeks ago&&&&&&&&114 MB
sqlcl&&&&&&&&&&&&&&latest&&&&&&&&&&&&&&980f85fc564e&&&&&&&&4 weeks ago&&&&&&&&463 MB
oraclelinux&&&&&&&&7-slim&&&&&&&&&&&&&&f005b5220b05&&&&&&&&7 weeks ago&&&&&&&&114 MB
Wouldn’t you love to clear some of that space up?
Remove Docker Images
docker rmi &image id&
Docker provides rmi option to delete images. Let go ahead and put this one to work and remove the first image
Danny: & docker rmi 62e
Error response from daemon: conflict: unable to delete 62e (must be forced)
- image is being used by stopped container be2d
Well what happened? Look closely, this image is being used by a stopped container. Alright so now we need to go find that container. On to our next command to get rid of the Docker Container.
Remove Docker Containers
docker rm &container id&
Again,&Docker provides an option, rm that allows us to delete any docker containers from our local system. Before we can run this in general, we need to find out Container IDs. In the situation above, we actually have it, but let’s user Docker to find these ids for us with the& ps option and the& -a parameter so we can see all the Docker Containers even if they are not running.
docker ps -a
Danny: & docker ps-a
CONTAINER ID&&&&&&&&IMAGE&&&&&&&&&&&&&&COMMAND&&&&&&&&&&&&&&&&&&CREATED&&&&&&&&&&&&STATUS&&&&&&&&&&&&&&&&&&&&PORTS&&&&&&&&&&&&&&NAMES
9f9d34aee084&&&&&&&&sqlslim&&&&&&&&&&&&&/bin/bash&&&&&&&&&&&&&&&4 minutes ago&&&&&&Exited (0) 4 minutes ago&&&&&&&&&&&&&&&&&&&&&&xenodochial_darwin
ed&&&&&&&&sqlslim&&&&&&&&&&&&&/bin/bash&&&&&&&&&&&&&&&4 minutes ago&&&&&&Exited (0) 4 minutes ago&&&&&&&&&&&&&&&&&&&&&&epic_boyd
63b123e4f50c&&&&&&&&oraclelinux&&&&&&&&&/bin/bash&&&&&&&&&&&&&&&24 hours ago&&&&&&&&Exited (0) 24 hours ago&&&&&&&&&&&&&&&&&&&&&&&&amazing_wilson
be2d&&&&&&&&oraclelinux&&&&&&&&&/bin/bash&&&&&&&&&&&&&&&24 hours ago&&&&&&&&Exited (0) 24 hours ago&&&&&&&&&&&&&&&&&&&&&&&&elated_elion
9e701197cddc&&&&&&&&pythonslim&&&&&&&&&&&/bin/bash&&&&&&&&&&&&&&&3 weeks ago&&&&&&&&Exited (0) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&keen_ramanujan
&&&&&&&&c133f715830e&&&&&&&&&/bin/bash&&&&&&&&&&&&&&&3 weeks ago&&&&&&&&Exited (0) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&zealous_spence
5a04b41413ce&&&&&&&&sqlslim&&&&&&&&&&&&&sql dbryant/eyeam...&&&3 weeks ago&&&&&&&&Exited (0) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&sharp_lichterman
b7c7569d21fc&&&&&&&&sqlslim&&&&&&&&&&&&&sql dbryant/eyeam...&&&3 weeks ago&&&&&&&&Exited (1) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&naughty_carson
f5&&&&&&&&sqlslim&&&&&&&&&&&&&sql sys/eyeamd1@1...&&&3 weeks ago&&&&&&&&Exited (1) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&kind_kare
6e&&&&&&&&sqlslim&&&&&&&&&&&&&sql sys/eyeamd1@1...&&&3 weeks ago&&&&&&&&Exited (1) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&blissful_austin
47efed596e8b&&&&&&&&sqlslim&&&&&&&&&&&&&sql sys@192.168.5...&&&3 weeks ago&&&&&&&&Exited (1) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&serene_hamilton
5b608a95492b&&&&&&&&sqlslim&&&&&&&&&&&&&sql dbryant/eyeam...&&&3 weeks ago&&&&&&&&Exited (1) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&friendly_hodgkin
bdabab59992b&&&&&&&&sqlslim&&&&&&&&&&&&&sql dbryant/eyeam...&&&3 weeks ago&&&&&&&&Exited (1) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&&&gifted_albattani
566da1f2d8a3&&&&&&&&99ad69730de1&&&&&&&&&/bin/sh -c 'unzip...&&&3 weeks ago&&&&&&&&Exited (127) 3 weeks ago&&&&&&&&&&&&&&&&&&&&&&loving_jones
Now we have everything we need to&get rid of those container and images. By the way, did you notice this guy here (be2d) about 4 rows down? That’s your offending Container keeping you from delete that image.
Stop & Remove All Docker Containers
I’m going to nuclear and stop and delete everything with a few “shortcuts.” Using the examples above, you can stop and delete individual container by simply entering the container id after the docker option. Here let’s blow them all away:
docker stop $(docker ps -a -q)
Here I am nesting two commands that you have already seen. The docker stop command with the& docker ps -a -q (the -q is for quiet — only show IDs). This in essence passes a list of Docker Container IDs to the docker stop command resulting in the stoppage of all Docker Containers.
Danny: & docker stop $(docker ps-a-q)
9f9d34aee084
63b123e4f50c
9e701197cddc
5a04b41413ce
b7c7569d21fc
47efed596e8b
5b608a95492b
bdabab59992b
566da1f2d8a3
Now that the Containers have been stopped, I’m going to nest another command with the docker ps -a -q command to remove/delete the Container
Danny: & docker rm $(docker ps-a-q)
9f9d34aee084
63b123e4f50c
9e701197cddc
5a04b41413ce
b7c7569d21fc
47efed596e8b
5b608a95492b
bdabab59992b
566da1f2d8a3
Danny: & docker ps-a
CONTAINER ID&&&&&&&&IMAGE&&&&&&&&&&&&&&COMMAND&&&&&&&&&&&&CREATED&&&&&&&&&&&&STATUS&&&&&&&&&&&&&&PORTS&&&&&&&&&&&&&&NAMES
Now you can see that all the Container are gone and move on with removing the Docker Images.
First re-issue the docker images command to get a look at the images that are currently out there,
Danny: & docker images
REPOSITORY&&&&&&&&&&TAG&&&&&&&&&&&&&&&&IMAGE ID&&&&&&&&&&&&CREATED&&&&&&&&&&&&SIZE
oraclelinux&&&&&&&&latest&&&&&&&&&&&&&&62e&&&&&&&&2 days ago&&&&&&&&&&225 MB
pythonslim&&&&&&&&&&latest&&&&&&&&&&&&&&2f61057fee22&&&&&&&&3 weeks ago&&&&&&&&318 MB
&none&&&&&&&&&&&&&&&&none&&&&&&&&&&&&&&&c133f715830e&&&&&&&&3 weeks ago&&&&&&&&310 MB
sqlslim&&&&&&&&&&&&latest&&&&&&&&&&&&&&6cab4fd15c1d&&&&&&&&3 weeks ago&&&&&&&&348 MB
oels&&&&&&&&&&&&&&&&latest&&&&&&&&&&&&&&f7&&&&&&&&3 weeks ago&&&&&&&&114 MB
sqlcl&&&&&&&&&&&&&&latest&&&&&&&&&&&&&&980f85fc564e&&&&&&&&4 weeks ago&&&&&&&&463 MB
oraclelinux&&&&&&&&7-slim&&&&&&&&&&&&&&f005b5220b05&&&&&&&&7 weeks ago&&&&&&&&114 MB
and make sure that we take care of that initial attempt that failed.
Danny: & dockerrmi 62e
Untagged: oraclelinux:latest
Untagged: oraclelinux@sha256:39470a3bde74c099eefec31d199e27cdcd445f7f7e9
Deleted: sha256:62ecacfcca77b032e2e5adb73bdc4d0fe8f7cebba932
Deleted: sha256:40c24f62a02f157ab14f4bc1fb899f716e42f2bd912
As you can see here, the image was successfully deleted. Now for the nuclear option! Getting rid of them all with, and you guessed it, another nested option.
docker rmi $(docker images -q)
Danny: & docker rmi $(docker images-q)
Untagged: pythonslim:latest
Deleted: sha256:2f61057fee22ed529119aba221b61afce076a05b81ddd01f932a7
Deleted: sha256:8061aeadf96f489bc5ed73be92c082e20
Deleted: sha256:ff49d613d58d807cd87ceac39da1aa9af1243
Deleted: sha256:c133fddf0cedbffe6f42fab7c23d9a1be5b84c9770dd
Deleted: sha256:68331ccc086054bfb451af10b330ded8f3ef96a56ad60
Deleted: sha256:87e67f661cf0f66f4c48bea88d8df5cfbf0bf43c312e57
Untagged: sqlslim:latest
Deleted: sha256:6cab4fd15c1d5eb9d45d1e5e22df91ec914571eaaf2cc679d6fbdc1
Deleted: sha256:5d0aeaa8485843efe7c8ac8a01fc107c66bc6d3c845ab1b83f291c
Deleted: sha256:3bf368d1bd62aaecba7590aff9d5e0be561bea2bc587
Deleted: sha256:99ad6ba793a685eca083fe3146b8fdab03aa8f
Deleted: sha256:ec69f880eb5d70d54eeae5b88b5cd0b45dfac10c47770
Untagged: oels:latest
Deleted: sha256:f76c8bb0edced8e42f
Deleted: sha256:f2af978d3170bcfe2c0befee0aafcdf98f7ed71df7419fed8b74
Deleted: sha256:d3ed559d4b6e9f907ef87dbfd8f461a6
Untagged: sqlcl:latest
Deleted: sha256:980f85fc564ee7ae9f224ad3000aef33714cebbef7efdb87d4be76
Deleted: sha256:bbf0c41ed3632412acd3fa69d519ea3bc753c26db83
Deleted: sha256:f2e6e5ce2a0e3f6a6ebbcd038d99ff0f65fe6dff285
Deleted: sha256:ef746b0fee0c3d5e9bca76dad0ac74dddca48b934ca4
Deleted: sha256:488bdfc5ae796dc06e374d0d95a60ab91f343e689e5ea865f119
Deleted: sha256:5a42e075a32bd55aadbafef8f6ce16ba8a3af1ba3c2
Deleted: sha256:dc8cbaef9eef57c1a68f8848d
Untagged: oraclelinux:7-slim
Untagged: oraclelinux@sha256:f3a78afd7b9f2b54b568dec3973efccf2b086d602fabb94069fb6d
Deleted: sha256:f005bde1fa070e515f81a9eab5157652
Deleted: sha256:dae53bfc95d17daad88955bcbaa93f3feeb91e6eac044ad81052
Danny: & docker images
REPOSITORY&&&&&&&&&&TAG&&&&&&&&&&&&&&&&IMAGE ID&&&&&&&&&&&&CREATED&&&&&&&&&&&&SIZE
There we have it Container and Images are now removed from your machine. Simply run your docker build command(s) recreate your images and containers.
For all intents and purposes, I created this post so that I could remember how I did this stuff a bit later ��
Also published on
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致只需 10 个命令就可体验 Docker Container
原文地址:&
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux
机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口(类似 iPhone 的
app)。几乎没有性能开销,可以很容易地在机器和数据中心中运行。最重要的是,他们不依赖于任何语言、框架或包装系统。
我们来运行 Docker 吧 !!!
在 Linux 主机上安装 docker& 包,这里是 CentOS 系统:
# yum install -y docker-io
启动 Docker 服务,作为一个启动进程来启用 TA
# s chkconfig docker on
Docker 推送 CentOS 镜像
# docker pull centos:latest
检测 docker 镜像
[root@karan-ws ~]# docker images
REPOSITORY
VIRTUAL SIZE
docker.io/centos
fd44297e2ddb
5 weeks ago
[root@karan-ws ~]#
创建 Docker 容器
[root@karan-ws ~]# docker create -ti --name="mona" centos bash
c7f9eb6b32ebacedeee720dbf29ccbfff15aa6
[root@karan-ws ~]#
开启你的 Docker 容器
# docker start mona
从你新创建的 Docker 容器中获取 IP 地址
[root@karan-ws ~]# docker inspect mona | grep -i ipaddress
"IPAddress": "172.17.0.1",
[root@karan-ws ~]#
连接到(登录)到你的 Docker 容器
[root@karan-ws ~]# docker attach mona
[root@c7f9eb6b32eb /]#
[root@c7f9eb6b32eb /]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[root@c7f9eb6b32eb /]# df -hFilesystem
Used Avail Use% Mounted on/dev/mapper/docker-253:1-f9eb6b32ebacedeee720dbf29ccbfff15aa6
0% /devshm
0% /dev/shmtmpfs
0% /runtmpfs
0% /tmp/dev/vda1
16% /etc/hoststmpfs
0% /run/secretstmpfs
0% /proc/kcore[root@c7f9eb6b32eb /]#
使用&ctrl+p+q 从 Docker 容器中分离,避免使用 exit 命令,因为 exit 命令会停止容器然后退出
[root@karan-ws ~]# docker ps
CONTAINER ID
c7f9eb6b32eb
centos:latest
9 minutes ago
Up 28 seconds
[root@karan-ws ~]#
停止和销毁容器
[root@karan-ws ~]# docker kill monamonamona
[root@karan-ws ~]#
[root@karan-ws ~]# docker psCONTAINER ID
[root@karan-ws ~]#
这是最基础的 Docker 操作,你可以执行一下体验 Docker Container 技术。
这十个命令也太简单了。。。。
--- 共有 1 条评论 ---
补充的再具体一点就好了:)
创建自己的镜像
& & tar -c . | docker import - yourImageName& & #tar -c .执行的时候需要切换到主目录下,镜像打包。“|”命令是管道,docker import - youImageName 创建一个空的镜像文件系统,并且引入tar 打包的内容,然后进行标签。
& & 也可以使用命令:docker load & /home/youTarFile.tar 来创建。
docker version&查看docker的版本号,包括客户端、服务端、依赖的Go等
docker info&查看系统(docker)层面信息,包括管理的images, containers数等
docker search &image&&在docker index中搜索image
docker pull &image&&从docker registry server 中下拉image
docker push &image|repository&&推送一个image或repository到registry
docker push &image|repository&:TAG&同上,指定tag
docker inspect &image|container&&查看image或container的底层信息
docker images&TODO&filter out the intermediate image layers (intermediate image layers 是什么)
docker images -a&列出所有的images
docker ps&默认显示正在运行中的container
docker ps -l&显示最后一次创建的container,包括未运行的
docker ps -a&显示所有的container,包括未运行的
docker logs &container&&查看container的日志,也就是执行命令的一些输出
docker rm &container...&&删除一个或多个container
docker rm `docker ps -a -q` 删除所有的container
docker ps -a -q | xargs docker rm&同上, 删除所有的container
docker rmi &image...&&删除一个或多个image
docker start/stop/restart &container&&开启/停止/重启container
docker start -i &container&&启动一个container并进入交互模式
docker attach &container&&attach一个运行中的container
docker run &image& &command&&使用image创建container并执行相应命令,然后停止
docker run -i -t &image& /bin/bash&使用image创建container并进入交互模式, login shell是/bin/bash
docker run -i -t -p &host_port:contain_port&&将container的端口映射到宿主机的端口
docker commit &container& [repo:tag]&将一个container固化为一个新的image,后面的repo:tag可选
docker build &path&&寻找path路径下名为的Dockerfile的配置文件,使用此配置生成新的image
docker build -t repo[:tag]&同上,可以指定repo和可选的tag
docker build - & &dockerfile&&使用指定的dockerfile配置文件,docker以stdin方式获取内容,使用此配置生成新的image
docker port &container& &container port&&查看本地哪个端口映射到container的指定端口,其实用docker ps&也可以看到}

我要回帖

更多关于 docker images 删除 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信