Docker入门(1)
21 June ’16
docker安装: ``` root@ubuntu:~/study/docker/mydockerbuild# curl -fsSL https://get.docker.com/ | sh
root@ubuntu:~/study/docker/mydockerbuild# docker run docker/whalesay cowsay boo
build自己的docker image
root@ubuntu:~/study/docker# mkdir mydockerbuild
root@ubuntu:~/study/docker# cd mydockerbuild
root@ubuntu:~/study/docker/mydockerbuild# vim Dockerfile
root@ubuntu:~/study/docker/mydockerbuild# cat Dockerfile
FROM docker/whalesay:latest
RUN apt-get -y update && apt-get install -y fortunes
CMD /usr/games/fortune -a | cowsay |
root@ubuntu:~/study/docker/mydockerbuild# docker run docker-whale
/ Experience is a good teacher, but she \
sends in terrific bills. |
– Minna Antrim, “Naked Truth and |
\ Veiled Allusions” /
\
\
\
.
## ## ==
## ## ## ===
/””””””””””””””"”___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
______ o __/
\ \ __/
____/
root@ubuntu:~/study/docker/mydockerbuild# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest 3179f50aaae0 About a minute ago 274.6 MB
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B
docker/whalesay latest 6b362a9f73eb 12 months ago 247 MB ``` tag并发布自己的image
首先要注册自己的docker账号 ``` root@ubuntu:~/study/docker/mydockerbuild# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest 3179f50aaae0 12 minutes ago 274.6 MB
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B
docker/whalesay latest 6b362a9f73eb 12 months ago 247 MB ``` 使用如下命令,打包自己的image:
![pic-1466493921127.png][1] ``` root@ubuntu:~/study/docker/mydockerbuild# docker tag 3179f50aaae0 jingyu1hao/docker-whale:latest
root@ubuntu:~/study/docker/mydockerbuild# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest 3179f50aaae0 13 minutes ago 274.6 MB
jingyu1hao/docker-whale latest 3179f50aaae0 13 minutes ago 274.6 MB
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B
docker/whalesay latest 6b362a9f73eb 12 months ago 247 MB
root@ubuntu:~/study/docker/mydockerbuild#
使用docker login命令登录Docker Hub:
root@ubuntu:~/study/docker/mydockerbuild# docker login –username=jingyu1hao –email=liujiazhu1987112@163.com
Warning: ‘–email’ is deprecated, it will be removed soon. See usage.
Password:
Login Succeeded
root@ubuntu:~/study/docker/mydockerbuild#
使用docker push 命令发布自己 的image到新的仓库:
root@ubuntu:~/study/docker/mydockerbuild# docker push jingyu1hao/docker-whale
The push refers to a repository [docker.io/jingyu1hao/docker-whale]
b057dcaa6a6a: Pushed
5f70bf18a086: Mounted from docker/whalesay
d061ee1340ec: Mounted from docker/whalesay
d511ed9e12e1: Mounted from docker/whalesay
091abc5148e4: Mounted from docker/whalesay
b26122d57afa: Mounted from docker/whalesay
37ee47034d9b: Mounted from docker/whalesay
528c8710fd95: Mounted from docker/whalesay
1154ba695078: Mounted from docker/whalesay
latest: digest: sha256:bc49e81c39299f626ce39641242d49af1490276065a7c759bda800274790e135 size: 8097
root@ubuntu:~/study/docker/mydockerbuild#
root@ubuntu:~/study/docker/mydockerbuild# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker-whale latest 3179f50aaae0 27 minutes ago 274.6 MB
jingyu1hao/docker-whale latest 3179f50aaae0 27 minutes ago 274.6 MB
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B
docker/whalesay latest 6b362a9f73eb 12 months ago 247 MB ``` 使用cocker pull 摘取远程新仓库到本地:
为测试,使用 docker rmi image-id 或 docker rmi image-name 先删除本地的 image : ``` root@ubuntu:~/study/docker/mydockerbuild# docker rmi -f 3179f50aaae0
Untagged: docker-whale:latest
Untagged: jingyu1hao/docker-whale:latest
Deleted: sha256:3179f50aaae0ab0aabf9d5e31b951d957e13bc2e38d4b2ed5c0d55543306c340
Deleted: sha256:7e398dea9fb43f4d17149e913442d3f136e85e002552839bfb85d3eda2b53b9d
root@ubuntu:~/study/docker/mydockerbuild#
root@ubuntu:~/study/docker/mydockerbuild# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B
docker/whalesay latest 6b362a9f73eb 12 months ago 247 MB
使用docker run命令从远程仓库拉取并加载一个新的image:
root@ubuntu:~/study/docker/mydockerbuild# docker run jingyu1hao/docker-whale
Unable to find image ‘jingyu1hao/docker-whale:latest’ locally
latest: Pulling from jingyu1hao/docker-whale
e190868d63f8: Already exists
909cd34c6fd7: Already exists
0b9bfabab7c1: Already exists
a3ed95caeb02: Already exists
00bf65475aba: Already exists
c57b6bcc83e3: Already exists
8978f6879e2f: Already exists
8eed3712d2cf: Already exists
b88d2e71d24f: Already exists
Digest: sha256:bc49e81c39299f626ce39641242d49af1490276065a7c759bda800274790e135
Status: Downloaded newer image for jingyu1hao/docker-whale:latest
/ Your nature demands love and your \
\ happiness depends on it. /
\
\
\
.
## ## ==
## ## ## ===
/””””””””””””””"”___/ ===
~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~
______ o __/
\ \ __/
____/
root@ubuntu:~/study/docker/mydockerbuild# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jingyu1hao/docker-whale latest 3179f50aaae0 31 minutes ago 274.6 MB
hello-world latest 94df4f0ce8a4 4 weeks ago 967 B
docker/whalesay latest 6b362a9f73eb 12 months ago 247 MB ``` [0]: http://www.linuxidc.com/Linux/2007-09/7399.htm [1]: ./pic-1466493921127.png
FROM docker/whalesay:latest RUN apt-get -y update && apt-get install -y fortunes CMD /usr/games/fortune -a | cowsay root@ubuntu:~/study/docker/mydockerbuild# docker run docker-whale _____________ / Experience is a good teacher, but she \ | sends in terrific bills. | | | | – Minna Antrim, “Naked Truth and | \ Veiled Allusions” / ————————————— \ \ \ ## . ## ## ## == ## ## ## ## === /””””””””””””””"”/ === ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ / ===- ~~~ ___ o __/ \ \ __/ ____/ root@ubuntu:~/study/docker/mydockerbuild# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker-whale latest 3179f50aaae0 About a minute ago 274.6 MB hello-world latest 94df4f0ce8a4 4 weeks ago 967 B 字符数:4790 字数:564段落数:148 小书匠 新建 保存 另存为 markdownFile[1].md