Docker Hub registry
列出主機的鏡像java
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這些信息都很重要,來自相同的倉庫咱們經過標籤
來指定要運行的鏡像git
languagedocker run -i -t ubuntu:14.04 /bin/bash docker run -i -t ubuntu:latest /bin/bash (不加標籤默認是`latest`)
我的以爲標籤的好處是對於來自相同的倉庫經過標籤來告訴docker我要運行的是哪一個鏡像web
尋找鏡像docker
languagedocker search [image name] docker pull [image name]...找到合適的後直接拉下來
建立和定製本身的鏡像shell
Dockerfile
來製做鏡像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
languagemkdir ubuntu cd ubuntu touch Dockerfile vim Dockerfile content: #this is my fiest image created by dockerfile FROM ubuntu:14.04 MAINTAINER adolph <test@126.com> RUN apt-get update #RUN apt-get install git
結果:ubuntu
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 <nalan3015@126.com> ---> 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 .vim
注意上述命令有個.
用來指定Dockerfile文件的位置bash
給鏡像添加標籤app
languagedocker tag [image id] [username]/[repository]:[tag name]
須要登陸Docker Hub帳號webapp
docker push [image name]
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)
這條命令很重要和難記,-m
和git commit -m
的做用相似,-a
指定做者,id指更改過的image的id
,adolph/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]