Centos下安装docker教程
通过yum安装
需要root或者能sudo的权限
yum包更新到最新
$sudoyumupdate
添加Dockeryum源
$sudotee/etc/yum.repos.d/docker.repo<<-'EOF' [dockerrepo] name=DockerRepository baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/ enabled=1 gpgcheck=1 gpgkey=https://yum.dockerproject.org/gpg EOF
安装Docker包
$sudoyuminstalldocker-engine
启动Docker守护进程
$sudoservicedockerstart
通过测试镜像运行一个容器来验证Docker是否安装正确
$sudodockerrunhello-world Unabletofindimage'hello-world:latest'locally latest:Pullingfromhello-world a8219747be10:Pullcomplete 91c95931e552:Alreadyexists hello-world:latest:Theimageyouarepullinghasbeenverified.Important:imageverificationisatechpreviewfeatureandshouldnotbereliedontoprovidesecurity. Digest:sha256:aa03e5d0d5553b4c3473e89c8619cf79df368babd1.7.1cf5daeb82aab55838d Status:Downloadednewerimageforhello-world:latest HellofromDocker. Thismessageshowsthatyourinstallationappearstobeworkingcorrectly. Togeneratethismessage,Dockertookthefollowingsteps: 1.TheDockerclientcontactedtheDockerdaemon. 2.TheDockerdaemonpulledthe"hello-world"imagefromtheDockerHub. (Assumingitwasnotalreadylocallyavailable.) 3.TheDockerdaemoncreatedanewcontainerfromthatimagewhichrunsthe executablethatproducestheoutputyouarecurrentlyreading. 4.TheDockerdaemonstreamedthatoutputtotheDockerclient,whichsentit toyourterminal. Totrysomethingmoreambitious,youcanrunanUbuntucontainerwith: $dockerrun-itubuntubash Formoreexamplesandideas,visit: http://docs.docker.com/userguide/
通过脚本安装
需要root或者能sudo的权限
yum包更新到最新
$sudoyumupdate
运行Docker安装脚本
$curl-sSLhttps://get.docker.com/|sh
这个脚本会添加docker.repo仓库并且安装Docker
启动Docker守护进程
$sudoservicedockerstart
通过测试镜像运行一个容器来验证Docker是否安装正确
$sudodockerrunhello-world
创建一个Docker用户组
docker守护进程绑定在Unixsocket而不是TCP端口。默认情况下Unixsocket属于root用户和具有sudo权限用户的使用范畴。出于这个原因,docker守护进程需要一直在root用户下面运行。
Toavoidhavingtousesudowhenyouusethedockercommand,createaUnixgroupcalleddockerandadduserstoit.Whenthedockerdaemonstarts,itmakestheownershipoftheUnixsocketread/writablebythedockergroup.
为了避免运行docker命令的时候需要使用sudo命令,创建一个叫docker的Unix用户组并将需要运行docker的用户添加进去。当开始运行docker守护进程,会令docker用户组的成员拥有Unixsocket的读写权限。
创建docker用户组并添加用户:
1.需要root或者能sudo的权限
2.创建docker用户组并添加用户
sudousermod-aGdockeryour_username
3.退出并且登录到your_username,如果在your_username下也建议退出再重新登录一次,这确保您的用户正在运行正确的权限。
4.验证运行docker已不再需要sudo命令
$dockerrunhello-world
开机运行docker
$sudochkconfigdockeron