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

[经验分享] ubuntu12.04 安装docker

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-2-27 10:41:14 | 显示全部楼层 |阅读模式
ubuntu12.04 安装docker

一、安装docker的前提条件

目前docker只支持64位CPU的架构(x86_64和AMD64)。不支持32位的CPU。运行linux3.8或者更高版本的内核,如版本过低建议进行内核的升级。
   
root@TS-V3RDS02:/home/david-dai# uname -a
Linux TS-V3RDS02 3.5.0-23-generic #35~precise1-Ubuntu SMP Fri Jan 25 17:13:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

升级内核:
   
sudo apt-get update
sudo apt-get install -y linux-image-generic-lts-trusty linux-headers-generic-lts-trusty
reboot
root@TS-V3RDS02:/home/david-dai# uname -a
Linux TS-V3RDS02 3.13.0-80-generic #124~precise1-Ubuntu SMP Tue Feb 23 18:05:11 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux


1、首先ubuntu上安装bridge包,才能允许docker使用桥接模式配置容器的IP

   
apt-get install -y bridge-utils
root@TS-V3RDS02:/home/david-dai# dpkg -l | grep bridge*
ii  bridge-utils                      1.5-2ubuntu7                 Utilities for configuring the Linux Ethernet bridge


2、修改网卡,使eth0为bridge模式

原网卡配置:

   
root@TS-V3RDS02:/home/david-dai# vim /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 172.22.64.31
        netmask 255.255.255.0

auto eth1
iface eth1 inet static
        address 221.228.208.184
        netmask 255.255.255.0
        gateway 221.228.208.49

up route add -net 172.22.0.0/16 gw 172.22.64.254


修改后网卡配置:

   
root@TS-V3RDS02:/home/david-dai# vim /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        #address 172.22.64.31
        #netmask 255.255.255.0
        #gateway 172.22.63.254
        # dns-* options are implemented by the resolvconf package, if installed

auto eth1
iface eth1 inet static
        address 221.228.208.184
        netmask 255.255.255.0
        gateway 221.228.208.49

auto zampbr0
iface zampbr0 inet static
address 172.22.64.31
netmask 255.255.255.0
bridge_ports eth0

up route add -net 172.22.0.0/16 gw 172.22.64.254

重启网卡:   
/etc/init.d/networking restart

查看网卡:

   
root@TS-V3RDS02:/home/david-dai# ifconfig
eth0      Link encap:Ethernet  HWaddr 54:9f:35:03:ca:ac  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:687076 errors:0 dropped:141 overruns:0 frame:0
          TX packets:1259077 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:102191731 (102.1 MB)  TX bytes:1192306912 (1.1 GB)
          Interrupt:35

eth1      Link encap:Ethernet  HWaddr 54:9f:35:03:ca:ad  
          inet addr:221.228.208.184  Bcast:221.228.208.255  Mask:255.255.255.0
          inet6 addr: fe80::569f:35ff:fe03:caad/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4511287 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3253383 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:909753738 (909.7 MB)  TX bytes:623700102 (623.7 MB)
          Interrupt:38

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:16436  Metric:1
          RX packets:160651189 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160651189 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:93150545838 (93.1 GB)  TX bytes:93150545838 (93.1 GB)

zampbr0   Link encap:Ethernet  HWaddr 54:9f:35:03:ca:ac  
          inet addr:172.22.64.31  Bcast:172.22.64.255  Mask:255.255.255.0
          inet6 addr: fe80::569f:35ff:fe03:caac/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:683159 errors:0 dropped:0 overruns:0 frame:0
          TX packets:987110 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:88727338 (88.7 MB)  TX bytes:1170344096 (1.1 GB)


如果在安装的时候报错,请安装一些依赖包:

   
sudo  apt-get install apt-transport-https
sudo apt-get  install apparmor

root@TS-V3RDS02:/opt/dockerconfig# vim /etc/apt/sources.list.d/docker.list
#deb https://get.docker.io/ubuntu docker main
deb https://apt.dockerproject.org/repo ubuntu-precise main



/etc/init/docker.conf 记得加上这个参数 ,指定本地的私有仓库,拉去镜像很快,本地维护镜像。
1
   
exec "$DOCKERD" $DOCKER_OPTS --raw-logs --insecure-registry 172.22.70.2:5000



重启docker

/etc/init.d/docker restart


安装pipwork

   
git clone https://github.com/jpetazzo/pipework
cp pipework/pipework /usr/bin/


创建docker容器

   
root@TS-V3RDS02:/opt/dockerconfig/scriprs# sh -x create_vm.sh
+ docker run -d -i -t --name=dmpdk44 -h dmpdk44 --net=none -v /vmdata/dmpdk44/:/var/bh/ -v /opt/dockerconfig/dockerenv:/opt/dockerconfig/ 172.22.70.2:5000/ubuntu /opt/dockerconfig/docker_init.sh
f9eb415a68a00403cd85fe0fcc40672fbc9c3637f119961f79df6f22fba73018
+ docker run -d -i -t --name=dmpdk45 -h dmpdk45 --net=none -v /vmdata/dmpdk45/:/var/bh/ -v /opt/dockerconfig/dockerenv:/opt/dockerconfig/ 172.22.70.2:5000/ubuntu /opt/dockerconfig/docker_init.sh
7a7dd6073317345eeae55ae4a7591a5bf3949ffaea7ebb3a46c8e8b0faa83777
+ docker run -d -i -t --name=dmpdk46 -h dmpdk46 --net=none -v /vmdata/dmpdk46/:/var/bh/ -v /opt/dockerconfig/dockerenv:/opt/dockerconfig/ 172.22.70.2:5000/ubuntu /opt/dockerconfig/docker_init.sh
517b10f3c0b289791a226ada10071c1b3de95abb3ee36a0d0afe04525a02973c
+ pipework zampbr0 dmpdk44 172.22.64.44/24@172.22.64.254
Warning: arping not found; interface may not be immediately reachable
+ pipework zampbr0 dmpdk45 172.22.64.45/24@172.22.64.254
Warning: arping not found; interface may not be immediately reachable
+ pipework zampbr0 dmpdk46 172.22.64.46/24@172.22.64.254
Warning: arping not found; interface may not be immediately reachable

root@TS-V3RDS02:/opt/dockerconfig/scriprs# vim create_vm.sh
docker run -d -i -t --name=dmpdk44 -h dmpdk44 --net=none -v /vmdata/dmpdk44/:/var/bh/  -v /opt/dockerconfig/dockerenv:/opt/dockerconfig/  172.22.70.2:5000/ubuntu /opt/dockerconfig/docker_init.sh
docker run -d -i -t --name=dmpdk45 -h dmpdk45 --net=none -v /vmdata/dmpdk45/:/var/bh/  -v /opt/dockerconfig/dockerenv:/opt/dockerconfig/  172.22.70.2:5000/ubuntu /opt/dockerconfig/docker_init.sh
docker run -d -i -t --name=dmpdk46 -h dmpdk46 --net=none -v /vmdata/dmpdk46/:/var/bh/  -v /opt/dockerconfig/dockerenv:/opt/dockerconfig/  172.22.70.2:5000/ubuntu /opt/dockerconfig/docker_init.sh
pipework zampbr0 dmpdk44 172.22.64.44/24@172.22.64.254
pipework zampbr0 dmpdk45 172.22.64.45/24@172.22.64.254
pipework zampbr0 dmpdk46 172.22.64.46/24@172.22.64.254


root@TS-V3RDS02:/opt/dockerconfig/dockerenv# cat /opt/dockerconfig/dockerenv/docker_init.sh
#! /bin/bash
cat /opt/dockerconfig/hosts_hadoop >> /etc/hosts
cat /opt/dockerconfig/hosts_docker >> /etc/hosts
/usr/sbin/sshd  #这样才允许ssh
/usr/sbin/cron  #这样才允许cron
/bin/bash
source /etc/profile


ping docker容器不通,原因是需要指定桥接网卡才可以,方法如下:



   
root@TS-V3RDS02:/opt/dockerconfig/scriprs# vi /etc/default/docker


DOCKER_OPTS="--dns 172.22.40.250 -b=zampbr0"


# Docker Upstart and SysVinit configuration file

#
# THIS FILE DOES NOT APPLY TO SYSTEMD
#
#   Please see the documentation for "systemd drop-ins":
#   https://docs.docker.com/engine/admin/systemd/
#

# Customize location of Docker binary (especially for development testing).
#DOCKERD="/usr/local/bin/dockerd"

# Use DOCKER_OPTS to modify the daemon startup options.
#DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

# If you need Docker to use an HTTP proxy, it can also be specified here.
#export http_proxy="http://127.0.0.1:3128/"

# This is also a handy place to tweak where Docker's temporary files go.
#export DOCKER_TMPDIR="/mnt/bigdrive/docker-tmp"

然后重启docker,pipwork添加ip,即可ping通
   
/etc/init.d/docker restart
docker ps -a
docker start f9eb415a68a0
docker exec -it f9eb415a68a0  /bin/bash
pipework zampbr0 dmpdk44 172.22.64.44/24@172.22.64.254
ps axu | grep docker
root     21558  0.1  0.0 1428948 32892 ?       Ssl  21:11   0:00 /usr/bin/dockerd --dns 172.22.40.250 -b=zampbr0 --raw-logs --insecure-registry 172.22.70.2:5000
david-dai@TS03:~/study$ ping 172.22.64.44
PING 172.22.64.44 (172.22.64.44) 56(84) bytes of data.
64 bytes from 172.22.64.44: icmp_req=1 ttl=63 time=1.67 ms
64 bytes from 172.22.64.44: icmp_req=2 ttl=63 time=0.649 ms


二、安装docker

参考docker官方文档:

https://docs.docker.com/engine/installation/linux/ubuntu/


    Install packages to allow apt to use a repository over HTTPS:

    $ sudo apt-get install -y --no-install-recommends \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common

    Add Docker’s official GPG key:

    $ curl -fsSL https://apt.dockerproject.org/gpg | sudo apt-key add -

    Verify that the key ID is 58118E89F3A912897C070ADBF76221572C52609D.

    $ apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D

      pub   4096R/2C52609D 2015-07-14
            Key fingerprint = 5811 8E89 F3A9 1289 7C07  0ADB F762 2157 2C52 609D
      uid                  Docker Release Tool (releasedocker) <docker@docker.com>

    Use the following command to set up the stable repository.

    实现如下功能:
    1
    2
        
    root@TS-V3RDS02:/opt/dockerconfig# vim /etc/apt/sources.list.d/docker.list
    deb https://apt.dockerproject.org/repo ubuntu-precise main


        Note: The lsb_release -cs sub-command below returns the name of your Ubuntu distribution, such asxenial.

    $ sudo add-apt-repository \
           "deb https://apt.dockerproject.org/repo/ \
           ubuntu-$(lsb_release -cs) \
           main"

    To enable the testing repository, you can edit /etc/apt/sources.list and add the word testing after mainon the appropriate line of the file. Do not use unstable repositories on production systems or for non-testing workloads.

        Note: Sometimes, in a distribution like Linux Mint, you might have to change ubuntu-$(lsb_release -cs) to your parent Ubuntu distribution. example: If you are using Linux Mint Rafaela, you could type inubuntu-trusty

Install Docker

    Update the apt package index.

    $ sudo apt-get update

    Install the latest version of Docker, or go to the next step to install a specific version. Any existing installation of Docker is replaced.

    Use this command to install the latest version of Docker:

    $ sudo apt-get -y install docker-engine

    可能需要增加:sudo apt-get -y install docker-engine --fix-missing

        Warning: If you have both stable and unstable repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command will always install the highest possible version, which will almost certainly be an unstable one.

    On production systems, you should install a specific version of Docker instead of always using the latest. This output is truncated. List the available versions.

    $ apt-cache madison docker-enginedocker-engine | 1.13.0-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
    docker-engine | 1.12.6-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
    docker-engine | 1.12.5-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages
    docker-engine | 1.12.4-0~ubuntu-xenial | https://apt.dockerproject.org/repo ubuntu-xenial/main amd64 Packages

    The contents of the list depend upon which repositories are enabled, and will be specific to your version of Ubuntu (indicated by the xenial suffix on the version, in this example). Choose a specific version to install. The second column is the version string. The third column is the repository name, which indicates which repository the package is from and by extension its stability level. To install a specific version, append the version string to the package name and separate them by an equals sign (=):

    $ sudo apt-get -y install docker-engine=<VERSION_STRING>

    The Docker daemon starts automatically.

    Verify that docker is installed correctly by running the hello-world image.

    $ sudo docker run hello-world

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Docker is installed and running. You need to use sudo to run Docker commands. Continue to Linux postinstall to allow non-privileged users to run Docker commands and for other optional configuration steps.
Upgrade Docker

To upgrade Docker, first run sudo apt-get update, then follow the installation instructions, choosing the new version you want to install.
Install from a package

If you cannot use Docker’s repository to install Docker, you can download the .deb file for your release and install it manually. You will need to download a new file each time you want to upgrade Docker.

    Go to https://apt.dockerproject.org/repo/pool/main/d/docker-engine/ and download the .deb file for the Docker version you want to install and for your version of Ubuntu.

        Note: To install a testing version, change the word main in the URL to testing. Do not use unstable versions of Docker in production or for non-testing workloads.

    Install Docker, changing the path below to the path where you downloaded the Docker package.

    $ sudo dpkg -i /path/to/package.deb

    The Docker daemon starts automatically.

    Verify that docker is installed correctly by running the hello-world image.

    $ sudo docker run hello-world

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.

Docker is installed and running. You need to use sudo to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps.
Upgrade Docker

To upgrade Docker, download the newer package file and repeat the installation procedure, pointing to the new file.
Uninstall Docker

    Uninstall the Docker package:

    $ sudo apt-get purge docker-engine

    Images, containers, volumes, or customized configuration files on your host are not automatically removed. To delete all images, containers, and volumes:

    $ sudo rm -rf /var/lib/docker

You must delete any edited configuration files manually.

运维网声明 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-347842-1-1.html 上篇帖子: Docker虚拟化技术系列之-DockerFile案例演练 下篇帖子: 常用Docker 镜像命令(二)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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