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 记得加上这个参数 ,指定本地的私有仓库,拉去镜像很快,本地维护镜像。
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
二、安装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.
实现如下功能:
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 main
on 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 usingLinux Mint Rafaela
, you could type inubuntu-trusty
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
orapt-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.
To upgrade Docker, first run sudo apt-get update
, then follow the installation instructions, choosing the new version you want to install.
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 totesting
. 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.
To upgrade Docker, download the newer package file and repeat the installation procedure, pointing to the new file.
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.
本文出自 “梅花香自苦寒来!” 博客,请务必保留此出处http://daixuan.blog.51cto.com/5426657/1901058
原文地址:http://daixuan.blog.51cto.com/5426657/1901058