ubuntu12.04 安装docker
一、安装docker的前提条件
目前docker只支持64位cpu的架构(x86_64和AMD64)。不支持32位的cpu。运行linux3.8或者更高版本的内核,如版本过低建议进行内核的升级。
root@TS-V3RDS02:/home/david-dai#uname-a LinuxTS-V3RDS023.5.0-23-generic#35~precise1-UbuntuSMPFriJan2517:13:26UTC2013x86_64x86_64x86_64GNU/Linux
升级内核:
sudoapt-getupdate sudoapt-getinstall-ylinux-image-generic-lts-trustylinux-headers-generic-lts-trusty reboot root@TS-V3RDS02:/home/david-dai#uname-a LinuxTS-V3RDS023.13.0-80-generic#124~precise1-UbuntuSMPTueFeb2318:05:11UTC2016x86_64x86_64x86_64GNU/Linux
1、首先ubuntu上安装bridge包,才能允许docker使用桥接模式配置容器的IP
apt-getinstall-ybridge-utils root@TS-V3RDS02:/home/david-dai#dpkg-l|grepbridge* iibridge-utils1.5-2ubuntu7UtilitiesforconfiguringtheLinuxEthernetbridge
2、修改网卡,使eth0为bridge模式
原网卡配置:
root@TS-V3RDS02:/home/david-dai#vim/etc/network/interfaces #Thisfiledescribesthenetworkinterfacesavailableonyoursystem #andhowtoactivatethem.Formoreinformation,seeinterfaces(5). #Theloopbacknetworkinterface autolo ifaceloinetloopback #Theprimarynetworkinterface autoeth0 ifaceeth0inetstatic address172.22.64.31 netmask255.255.255.0 autoeth1 ifaceeth1inetstatic address221.228.208.184 netmask255.255.255.0 gateway221.228.208.49 uprouteadd-net172.22.0.0/16gw172.22.64.254
修改后网卡配置:
root@TS-V3RDS02:/home/david-dai#vim/etc/network/interfaces #Thisfiledescribesthenetworkinterfacesavailableonyoursystem #andhowtoactivatethem.Formoreinformation,seeinterfaces(5). #Theloopbacknetworkinterface autolo ifaceloinetloopback #Theprimarynetworkinterface autoeth0 ifaceeth0inetstatic #address172.22.64.31 #netmask255.255.255.0 #gateway172.22.63.254 #dns-*optionsareimplementedbytheresolvconfpackage,ifinstalled autoeth1 ifaceeth1inetstatic address221.228.208.184 netmask255.255.255.0 gateway221.228.208.49 autozampbr0 ifacezampbr0inetstatic address172.22.64.31 netmask255.255.255.0 bridge_portseth0 uprouteadd-net172.22.0.0/16gw172.22.64.254
重启网卡:
/etc/init.d/networkingrestart
查看网卡:
root@TS-V3RDS02:/home/david-dai#ifconfig eth0Linkencap:EthernetHWaddr54:9f:35:03:ca:ac UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1 RXpackets:687076errors:0dropped:141overruns:0frame:0 TXpackets:1259077errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:102191731(102.1MB)TXbytes:1192306912(1.1GB) Interrupt:35 eth1Linkencap:EthernetHWaddr54:9f:35:03:ca:ad inetaddr:221.228.208.184Bcast:221.228.208.255Mask:255.255.255.0 inet6addr:fe80::569f:35ff:fe03:caad/64Scope:Link UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1 RXpackets:4511287errors:0dropped:0overruns:0frame:0 TXpackets:3253383errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:1000 RXbytes:909753738(909.7MB)TXbytes:623700102(623.7MB) Interrupt:38 loLinkencap:LocalLoopback inetaddr:127.0.0.1Mask:255.0.0.0 inet6addr:::1/128Scope:Host UPLOOPBACKRUNNINGMTU:16436Metric:1 RXpackets:160651189errors:0dropped:0overruns:0frame:0 TXpackets:160651189errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:0 RXbytes:93150545838(93.1GB)TXbytes:93150545838(93.1GB) zampbr0Linkencap:EthernetHWaddr54:9f:35:03:ca:ac inetaddr:172.22.64.31Bcast:172.22.64.255Mask:255.255.255.0 inet6addr:fe80::569f:35ff:fe03:caac/64Scope:Link UPBROADCASTRUNNINGMULTICASTMTU:1500Metric:1 RXpackets:683159errors:0dropped:0overruns:0frame:0 TXpackets:987110errors:0dropped:0overruns:0carrier:0 collisions:0txqueuelen:0 RXbytes:88727338(88.7MB)TXbytes:1170344096(1.1GB)
如果在安装的时候报错,请安装一些依赖包:
sudoapt-getinstallapt-transport-https sudoapt-getinstallapparmor root@TS-V3RDS02:/opt/dockerconfig#vim/etc/apt/sources.list.d/docker.list #debhttps://get.docker.io/ubuntudockermain debhttps://apt.dockerproject.org/repoubuntu-precisemain
/etc/init/docker.conf记得加上这个参数,指定本地的私有仓库,拉去镜像很快,本地维护镜像。
exec"$DOCKERD"$DOCKER_OPTS--raw-logs--insecure-registry172.22.70.2:5000
重启docker
/etc/init.d/docker restart
安装pipwork
gitclonehttps://github.com/jpetazzo/pipework cppipework/pipework/usr/bin/
创建docker容器
root@TS-V3RDS02:/opt/dockerconfig/scriprs#sh-xcreate_vm.sh +dockerrun-d-i-t--name=dmpdk44-hdmpdk44--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 +dockerrun-d-i-t--name=dmpdk45-hdmpdk45--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 +dockerrun-d-i-t--name=dmpdk46-hdmpdk46--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 +pipeworkzampbr0dmpdk44172.22.64.44/24@172.22.64.254 Warning:arpingnotfound;interfacemaynotbeimmediatelyreachable +pipeworkzampbr0dmpdk45172.22.64.45/24@172.22.64.254 Warning:arpingnotfound;interfacemaynotbeimmediatelyreachable +pipeworkzampbr0dmpdk46172.22.64.46/24@172.22.64.254 Warning:arpingnotfound;interfacemaynotbeimmediatelyreachable root@TS-V3RDS02:/opt/dockerconfig/scriprs#vimcreate_vm.sh dockerrun-d-i-t--name=dmpdk44-hdmpdk44--net=none-v/vmdata/dmpdk44/:/var/bh/-v/opt/dockerconfig/dockerenv:/opt/dockerconfig/172.22.70.2:5000/ubuntu/opt/dockerconfig/docker_init.sh dockerrun-d-i-t--name=dmpdk45-hdmpdk45--net=none-v/vmdata/dmpdk45/:/var/bh/-v/opt/dockerconfig/dockerenv:/opt/dockerconfig/172.22.70.2:5000/ubuntu/opt/dockerconfig/docker_init.sh dockerrun-d-i-t--name=dmpdk46-hdmpdk46--net=none-v/vmdata/dmpdk46/:/var/bh/-v/opt/dockerconfig/dockerenv:/opt/dockerconfig/172.22.70.2:5000/ubuntu/opt/dockerconfig/docker_init.sh pipeworkzampbr0dmpdk44172.22.64.44/24@172.22.64.254 pipeworkzampbr0dmpdk45172.22.64.45/24@172.22.64.254 pipeworkzampbr0dmpdk46172.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="--dns172.22.40.250-b=zampbr0" #DockerUpstartandSysVinitconfigurationfile # #THISFILEDOESNOTAPPLYTOSYSTEMD # #Pleaseseethedocumentationfor"systemddrop-ins": #https://docs.docker.com/engine/admin/systemd/ # #CustomizelocationofDockerbinary(especiallyfordevelopmenttesting). #DOCKERD="/usr/local/bin/dockerd" #UseDOCKER_OPTStomodifythedaemonstartupoptions. #DOCKER_OPTS="--dns8.8.8.8--dns8.8.4.4" #IfyouneedDockertouseanHTTPproxy,itcanalsobespecifiedhere. #exporthttp_proxy="http://127.0.0.1:3128/" #ThisisalsoahandyplacetotweakwhereDocker'stemporaryfilesgo. #exportDOCKER_TMPDIR="/mnt/bigdrive/docker-tmp"
然后重启docker,pipwork添加ip,即可ping通
/etc/init.d/dockerrestart dockerps-a dockerstartf9eb415a68a0 dockerexec-itf9eb415a68a0/bin/bash pipeworkzampbr0dmpdk44172.22.64.44/24@172.22.64.254 psaxu|grepdocker root215580.10.0142894832892?Ssl21:110:00/usr/bin/dockerd--dns172.22.40.250-b=zampbr0--raw-logs--insecure-registry172.22.70.2:5000 david-dai@TS03:~/study$ping172.22.64.44 PING172.22.64.44(172.22.64.44)56(84)bytesofdata. 64bytesfrom172.22.64.44:icmp_req=1ttl=63time=1.67ms 64bytesfrom172.22.64.44:icmp_req=2ttl=63time=0.649ms
二、安装docker
参考docker官方文档:
https://docs.docker.com/engine/installation/linux/ubuntu/
Install packages to allow
apt
to use a repository over HTTPS:$sudoapt-getinstall-y--no-install-recommends\ apt-transport-https\ ca-certificates\ curl\ software-properties-common
Add Docker’s official GPG key:
$curl-fsSLhttps://apt.dockerproject.org/gpg|sudoapt-keyadd-
Verify that the key ID is
58118E89F3A912897C070ADBF76221572C52609D
.$apt-keyfingerprint58118E89F3A912897C070ADBF76221572C52609D pub4096R/2C52609D2015-07-14 Keyfingerprint=58118E89F3A912897C070ADBF76221572C52609D uidDockerReleaseTool(releasedocker)<docker@docker.com>
Use the following command to set up thestablerepository.
实现如下功能:
root@TS-V3RDS02:/opt/dockerconfig#vim/etc/apt/sources.list.d/docker.list debhttps://apt.dockerproject.org/repoubuntu-precisemain
-
Note: The
lsb_release -cs
sub-command below returns the name of your Ubuntu distribution,such asxenial
.$sudoadd-apt-repository\ "debhttps://apt.dockerproject.org/repo/\ ubuntu-$(lsb_release-cs)\ main"
To enable the
testing
repository,you can edit/etc/apt/sources.list
and add the wordtesting
aftermain
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
Install Docker
Update the
apt
package index.$sudoapt-getupdate
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:
$sudoapt-get-yinstalldocker-engine
可能需要增加:sudoapt-get-yinstalldocker-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-cachemadisondocker-enginedocker-engine|1.13.0-0~ubuntu-xenial|https://apt.dockerproject.org/repoubuntu-xenial/mainamd64Packages docker-engine|1.12.6-0~ubuntu-xenial|https://apt.dockerproject.org/repoubuntu-xenial/mainamd64Packages docker-engine|1.12.5-0~ubuntu-xenial|https://apt.dockerproject.org/repoubuntu-xenial/mainamd64Packages docker-engine|1.12.4-0~ubuntu-xenial|https://apt.dockerproject.org/repoubuntu-xenial/mainamd64Packages
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 (=
):
$sudoapt-get-yinstalldocker-engine=<VERSION_STRING>
The Docker daemon starts automatically.
Verify that
docker
is installed correctly by running thehello-world
image.$sudodockerrunhello-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 usesudo
to run Docker commands. Continue toLinux postinstallto allow non-privileged users to run Docker commands and for other optional configuration steps.
Upgrade Docker
To upgrade Docker,first runsudo apt-get update
,then follow theinstallation 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 tohttps://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.
$sudodpkg-i/path/to/package.deb
The Docker daemon starts automatically.
Verify that
Post-installation steps for Linuxto allow non-privileged users to run Docker commands and for other optional configuration steps.
installation procedure,pointing to the new file.
Uninstall Docker
Uninstall the Docker package:
$sudoapt-getpurgedocker-engine
Images,containers,volumes,or customized configuration files on your host are not automatically removed. To delete all images,and volumes:
$sudorm-rf/var/lib/docker
You must delete any edited configuration files manually.
原文链接:https://www.f2er.com/ubuntu/354396.html