设为首页 收藏本站
查看: 1113|回复: 0

[经验分享] Docker(1)Installation and Images Containers

[复制链接]

尚未签到

发表于 2016-1-11 12:39:03 | 显示全部楼层 |阅读模式
Docker(1)Installation and Images Containers

1. Installation
MAC
I just download the file and install from here https://docs.docker.com/installation/mac/.
> docker --version
Docker version 1.6.2, build 7c8fca2

UBUNTU
> sudo apt-get install -y docker.io
> docker --version
Docker version 1.5.0, build a8a31ef

Start the docker service
> sudo service docker start

Once your docker service is running.
> carl@ubuntu-pilot:~$ ps -ef | grep docker
root      1685     1  0 16:47 ?        00:00:00 /usr/bin/docker -d -H fd://

2. Introduction
docker virtualization is based on the operation system layer, the others are based on hardware layer.

virtual machines —> App A, B - Bins/Libs - Guest OS
Docker —> App B - Bins/Libs

Based on that, one single machine can run thousands of Docker container.

Basic Term
Image: image can use to create docker container, it is template. It is readonly.
Container: Docker run the applications in Containers. Container is on top of Image.
Repository:Repository contains a lot of images.
one repository —> a lot of images —> container on top of image —> application run on top of container
3. Use that on Ubuntu - Images
search the Image
> sudo docker search memcached

Pull the Image
> sudo docker pull memcached

List all the Images
> sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
node                0.12                f9ba67676f8f        5 days ago          711.8 MB
node                0.12.4              f9ba67676f8f        5 days ago          711.8 MB
node                latest              f9ba67676f8f        5 days ago          711.8 MB

The list information includes which repository, image tag, image id and when it is created, what is the size of that images.

If we specify the tag, it will go with that tag, if not, it will go with latest.

Use Dockerfile to create a image
http://dockerpool.com/static/books/docker_practice/dockerfile/README.html

> mkdir ubuntu-ruby
> cat Dockerfile
#This is comment
FROM ubuntu:14.04
MAINTAINER Carl Luo <luohuazju@gmail.com>
RUN apt-get -qq update
RUN apt-get -qqy install ruby ruby-dev

Build the image
> sudo docker build -t="ubuntu-ruby:v1" .
Sending build context to Docker daemon 2.048 kB
Sending build context to Docker daemon
Step 0 : FROM ubuntu:14.04
---> 6d4946999d4f
Step 1 : MAINTAINER Docker GreenHand <luohuazju@gmail.com>
---> Using cache
---> 873801ee719d
Step 2 : RUN apt-get -qq update
---> Using cache
---> 4c6db71f543f
Step 3 : RUN apt-get -qqy install ruby ruby-dev
---> Using cache
---> d6f6754ff5dc
Successfully built d6f6754ff5dc

Start the image
> sudo docker run -t -i ubuntu-ruby:v1 /bin/bash

Change the tag
> sudo docker tag d6f6754ff5dc ubuntu-ruby:v2

Save and Load the Image
Save the docker image to your local file system
> sudo docker save -o /home/carl/install/ubuntu-ruby.v1.tar ubuntu-ruby:v1

Load the image from local file
> sudo docker load --input /home/carl/install/ubuntu-ruby.v1.tar

Remove the local images
> sudo docker rmi mongo:3.0

But sometimes, it will complain about remaining containers
> sudo docker rmi centos:centos7
Error response from daemon: Conflict, cannot delete 7322fbe74aa5 because the container 7adc92814fdb is using it, use -f to force
FATA[0000] Error: failed to remove one or more images  

Solution:
> sudo docker rmi -f centos:centos7

4. Containers
There are 2 types of starting a container, one is to start a container based on a new image; the other is to resume a stopped container.

Pull one latest ubuntu OS
> sudo docker pull ubuntu

Start the container and run hello sillycat
> sudo docker run ubuntu:14.04 /bin/echo 'hello sillycat'

Start the bash command
> sudo docker run -t -i ubuntu:14.04 /bin/bash

Check the current running container
> sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
4cef2c743fc0        ubuntu:14.04        "/bin/bash"         4 minutes ago       Up 2 minutes                            drunk_rosalind

Check the docker log
> sudo docker logs drunk_rosalind

Command to check all the container
> sudo docker ps -a

Start the container
> sudo docker stop drunk_rosalind

-d parameter will put the container running in the back, but sometimes we need to login in the container.

Star the ubuntu container with this command
> sudo docker run -idt ubuntu

> sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
e0b6b07723c8        ubuntu:14.04        "/bin/bash"         5 seconds ago       Up 5 seconds                            angry_goldstine

> sudo docker attach angry_goldstine

export the snapshot of container to local file
> sudo docker export 7fc47beabcb9 > /home/carl/install/ubuntu.tar

import the snapshot to image
> cat ubuntu.tar | sudo docker import - test/ubuntu:v1.0
> sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
test/ubuntu         v1.0                213dbae711c1        27 seconds ago      188.1 MB

It can be imported from one REMOTE URL
sudo docker import http://xx.xx.xx/ubuntu.tar test/ubuntu:v1

Remote the Container
> sudo docker rm insane_yonath


References:
https://github.com/docker/docker
https://docs.docker.com/installation/mac/

http://aws.amazon.com/elasticmapreduce/

docker references
https://kitematic.com/
https://docs.docker.com/installation/mac/
https://docs.docker.com/installation/
http://segmentfault.com/a/1190000000366923
http://www.jianshu.com/p/26f15063de7d
http://www.infoq.com/cn/articles/docker-containers
http://www.infoq.com/cn/news/2014/12/shopify-docker-experience
http://cn.soulmachine.me/blog/20131026/
https://www.gitbook.com/book/yeasy/docker_practice/details
http://tech.uc.cn/?p=2726
http://dockone.io/article/126
http://dockerpool.com/static/books/docker_practice/install/centos.html

docker on raspberry
https://resin.io/blog/docker-on-raspberry-pi-in-4-simple-steps/
http://blog.xebia.com/2014/08/25/docker-on-a-raspberry-pi/

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-163053-1-1.html 上篇帖子: 使用Docker registry镜像创建私有仓库 下篇帖子: 搭建本地测试的Docker Registry
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表