码迷,mamicode.com
首页 > 其他好文 > 详细

1.7.0版本docker安装与使用

时间:2015-06-26 13:09:13      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:docker

服务器是ubuntu server 14.04,内核:3.13.0-32-generic  ,  硬件是dell R520

一、安装

方法一:

通过系统自带包安装

Ubuntu 14.04 版本系统中已经自带了 Docker 包,可以直接安装。

$ sudo apt-get update

$ sudo apt-get install -y docker.io

$ sudo ln -sf /usr/bin/docker.io /usr/local/bin/docker

$ sudo sed -i ‘$acomplete -F _docker docker‘ /etc/bash_completion.d/docker.io


方法二:

通过Docker源安装最新版本

要想安装最新版本的Docker需要使用Docker源来安装

# apt-get -y install apt-transport-https

# apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9

# bash -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list"

# apt-get update

# apt-get -y install lxc-docker

# docker -v   //查看docker版本

# ps -ef | grep docker   

root     17311     1  0 Feb13 ?        00:00:43 /usr/bin/docker -d


2、下载tar包并加入镜像里

一般下载镜像的时候,都是先docker search image_name,然后docker pull image_name

但由于最近GFW屏蔽了网络,在现在的时候会出现以下错误,根本pull不了镜像。

Pull ingrepository centos

2014/05/19 13:35:11 Gethttps://cdn-registry-1.docker.io/v1/repositories/library/centos/tagsread tcp162.159.253.251:443: connection timed out


所以为了解决此问题,我就从别的地方下载了打包好的tar(后边会解释然后自己打包的),然后使用docker load导入先下载(有centos与ubuntu)

wget http://docker.widuu.com/ubuntu.tar

wget http://docker.widuu.com/centos.tar

加入到镜像里

#docker load -i centos.tar
#docker load -i ubuntu.tar

查看镜像列表

#docker images

REPOSITORY        TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
<none>            <none>              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu         latest               963b9d0e10ba        3 monthsago         155 MB

给centos的改个名

#docker tag 607 centos:latest

#docker images
REPOSITORY         TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos             latest              607347d2a946        3 months ago        300.2 MB
ubuntu/widuu            latest              963b9d0e10ba        3 monthsago         155 MB

测试镜像是否可用

#docker run centos /bin/echo "hello,i‘m centos system"

hello,i‘mcentos system
#docker run ubuntu/widuu /bin/echo "hello,i‘m ubuntu system"
hello,i‘mubuntu system

使用交换模式

#docker run -i -t centos /bin/bash

bash-4.1#ifconfig
eth0      Link encap:Ethernet  HWaddr BA:08:86:7F:F8:48 
          inet addr:172.17.0.4  Bcast:0.0.0.0 Mask:255.255.0.0
          inet6 addr: fe80::b808:86ff:fe7f:f848/64Scope:Link
          UP BROADCAST RUNNING  MTU:1500 Metric:1
          RX packets:6 errors:0 dropped:2overruns:0 frame:0
          TX packets:2 errors:0 dropped:0overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:488 (488.0 b)  TX bytes:168 (168.0 b)
  
lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:1500 Metric:1
          RX packets:0 errors:0 dropped:0overruns:0 frame:0
          TX packets:0 errors:0 dropped:0overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
  
bash-4.1# exit

退出有2种方式,一种是完全退出,使用exit;另外一中是不完全退出,使用ctrl-p与ctrl-q

这样你不是完全退出了,但容器状态还是存在。

可用使用docker attach CONTAINER ID来重新进入。

如果你是完全退出了,docker容器状态显示Exited,需要重新启动docker容器,在使用attach进入.

docker start CONTAINER ID

docker attach CONTAINER ID


二、私有库

由于GFW,所以玩docker没办法pullpush,并且为了安全考虑,为了解决就搭建了私有库。

# git clone https://github.com/dotcloud/docker-registry.git
# cd docker-registry
# cd config
# cp config_sample.yml config.yml
# cd ..
# apt-get install python-pip gunicorn build-essential python-dev libevent-dev python-pip liblzma-dev -y
# pip install -r requirements.txt
# gunicorn -k gevent --max-requests 100 --graceful-timeout 3600 -t 3600 -b localhost:5000 -w 8 -D --access-logfile /tmp/gunicorn.log  docker_registry.wsgi:application

客户端推送镜像到私有库1、  先注册账号

# docker login localhost:5000
依次输入你的账号、密码、email2、给提交的镜像打标签

# docker ps 
CONTAINER ID        IMAGE                COMMAND             CREATED             STATUS              PORTS               NAMES
504d16302ad4       
 jdeathe/centos-ssh   "/bin/bash"         About an hour ago   Up 42 
minutes       22/tcp              serene_bardeen  
    
# docker commit 504d16302ad4 centos:v1
b47276971c2db84bd76659da86a4ea5bda227f008c5004152232183066f20533

# docker images 
REPOSITORY           TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
centos               v1                  b47276971c2d        7 seconds ago       376.8 MB
jdeathe/centos-ssh   latest              b071db8f6e23        4 weeks ago         238 MB







http://docker.widuu.com/ 

本文出自 “从心开始” 博客,请务必保留此出处http://hao360.blog.51cto.com/5820068/1665857

1.7.0版本docker安装与使用

标签:docker

原文地址:http://hao360.blog.51cto.com/5820068/1665857

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!