资讯专栏INFORMATION COLUMN

Working with Docker Images

wangxinarhat / 1975人阅读

摘要:注意上述命令有个用来指定文件的位置给镜像添加标签需要登录账号总结查看镜像查找镜像这条命令很重要和难记,和的作用类似,指定作者指更改过的的,是新的的名字后面要指定的地址

目标

本地主机管理镜像

创建自己的镜像

上传镜像到Docker Hub registry

Listing images on the host
  

列出主机的镜像

shelladolph@geek:~$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
ubuntu              14.04               07f8e8c5e660        12 days ago         188.3 MB
hello-world         latest              91c95931e552        3 weeks ago         910 B
training/webapp     latest              31fa814ba25a        11 months ago       278.8 MB

镜像来自的仓库,标签和Id这些信息都很重要,来自相同的仓库我们通过标签来指定要运行的镜像

languagedocker run -i -t ubuntu:14.04 /bin/bash
docker run -i -t ubuntu:latest /bin/bash     (不加标签默认是`latest`)
  

个人觉得标签的好处是对于来自相同的仓库通过标签来告诉docker我要运行的是哪个镜像

Finding images
  

寻找镜像

languagedocker search [image name]
docker pull [image name]...找到合适的后直接拉下来
Creating our own images
  

创建和定制自己的镜像

更改现有镜像并提交(保存)

使用Dockerfile来制作镜像

Updating and committing an image
languagedocker run -i -t ubuntu:14.04 /bin/bash
root@5bc673e32e0a:/#apt-get install git
root@5bc673e32e0a:/#exit
sudo docker commit -m "install git" -a "adolph" 0b2616b0e5a8 adolph/ubuntu:14.04

output:4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c
Building an image from a Dockerfile
languagemkdir ubuntu
cd ubuntu
touch Dockerfile
vim Dockerfile
content:

#this is my fiest image created by dockerfile
FROM ubuntu:14.04
MAINTAINER adolph 
RUN apt-get update
#RUN apt-get install git

结果:

languageadolph@geek:~/ubuntu$ sudo docker build -t adolph-dockerfile/ubuntu:14.04 .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon 
Step 0 : FROM ubuntu:14.04
 ---> 07f8e8c5e660
Step 1 : MAINTAINER adolph 
 ---> Running in 241ad7c398c3
 ---> 10d866905c1a
Removing intermediate container 241ad7c398c3
Step 2 : RUN apt-get update
 ---> Running in 826db7ff28e6
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
。。。。。。。。。

sudo docker build -t adolph-dockerfile/ubuntu:14.04 .

注意上述命令有个.用来指定Dockerfile文件的位置

Setting tags on an image
  

给镜像添加标签

languagedocker tag [image id] [username]/[repository]:[tag name]
Push an image to Docker Hub
  

需要登录Docker Hub账号

docker push [image name]

Remove an image from the host

docker rmi [image name]

总结
languagedocker images...查看docker镜像
docker search [images name]...查找镜像

sudo docker commit -m "install git" -a "adolph" 0b2616b0e5a8(old image id) adolph/ubuntu:14.04(new image name with tag 14.04)
这条命令很重要和难记,-mgit commit -m的作用类似,-a指定作者,id指更改过的image的idadolph/ubuntu是新的image的名字

languagedocker build -t adolph-dockerfile/ubuntu:14.04 .
后面要指定dockerfile的地址
docker tag [image id] [username]/[repository]:[tag name]
docker push [image name]
docker rmi [image name]

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/26389.html

相关文章

  • Working with Docker Hub

    摘要:到目前为止我们已经学习了如何使用命令行在主机上运行。是由公司维护的公共注册仓库。其中有两个结果,。第二个表示它来自于一位叫的用户的仓库。第一个结果没有显示列出仓库则意味着它是受信任的官方顶级名称空间存储库。将仓库名和镜像名分割开。 Working with Docker Hub 到目前为止我们已经学习了如何使用命令行在主机上运行Docker。你已经学习了如何下载镜像,如何从已经存在的镜...

    Charles 评论0 收藏0
  • Working with Containers

    摘要:先回顾之前学习过的一些命令交互式运行运行守护进程容器列表显示容器的标准输出命令格式能干什么显示后能执行的命令命令使用查看特定命令的使用方式中运行一个应用参数表示将容器内部要用到的网络端口映射到主机显示容器的详细信 showImg(http://7vihfm.com1.z0.glb.clouddn.com/2015-3-28-weekly-summary.jpeg); 先回顾之前学习过...

    codecraft 评论0 收藏0
  • 走进docker(03):如何绕过docker运行hello-world?

    摘要:相关工具本文将用到三个工具,分别是和。根据生成的的就是运行容器时需要的东西的集合。使用运行该有了后,就可以用来运行该容器了这里直接用的代替命令,如果你自己编译了的,那么用命令也是一样的。 上一篇介绍了image的格式,这里我们就来用一下hello-world这个image,看怎么输出和docker run hello-world同样的内容。 相关工具 本文将用到三个工具,分别是skop...

    robin 评论0 收藏0
  • Deploy Django Project of local MySQL DB using Dock

    摘要: Docker in Windows Normally, those kinds of things will be much more troublesome when you want to run them in Windows compare to in Linux. However, Docker has made quite user-friendly for Window...

    Juven 评论0 收藏0
  • Deploy Django Project of local MySQL DB using Dock

    摘要: Docker in Windows Normally, those kinds of things will be much more troublesome when you want to run them in Windows compare to in Linux. However, Docker has made quite user-friendly for Window...

    Keagan 评论0 收藏0

发表评论

0条评论

wangxinarhat

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<