centos7.x docker安装及配置,持续更新

1. 安装docker-ce [root],ce为docker社区版,免费,ee版为企业版,收费

列出所有已安装docker

 # rpm -qa | grep docker

删除已安装docker

 # rpm -e rpmname

安装docker-ce

 # yum install docker-ce.x86_64 # 此命令会自动安装相关依赖包

配置Daocloud加速

 # curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://8ad7943c.m.daocloud.io

2. 开启dock服务,并设置开机自启 [root]

 # systemctl start docker
# systemctl enable docker.service

3. 测试docker [root]

 # docker run hello-world # 会弹出如下信息,说明安装成功
Hello from Docker!
This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps:
. The Docker client contacted the Docker daemon.
. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal. To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID:
https://cloud.docker.com/ For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
 # docker info #此命令可以查看dock内image和container信息

4. 使特定普通用户可以执行dock命令 [root]

 # visudo

在最下方加入此行,此行会允许特定用户以sudo方式运行docker,第一次运行时要求输入该特定用户的密码,以后每隔5分钟重复运行docker命令时需要输入密码:

 #docker
username        ALL=(ALL) /usr/bin/docker

下面这行的区别在于,不需要输入sudo密码,但是并不安全

 #docker
username        ALL=(ALL) NOPASSWD: /usr/bin/docker

设置/usr/bin/docker别名

 # alias docker="sudo /usr/bin/docker" 

直接在命令行输入上述命令时,此命令不会永久生效,如果想永久生效,将其加入对应用户的.bashrc中即可

 vim ~/.bashrc
 # .bashrc

 # User specific aliases and functions

 alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias docker="sudo /usr/bin/docker" # Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
...

5. 测试 [username]

配置完上述命令之后,指定的普通用户就可以直接运行docker命令了

 # dock info

参考自:

http://cloud.51cto.com/art/201508/488478.htm

http://www.jianshu.com/p/e9b6f5a6f198

https://segmentfault.com/a/1190000007875949

上一篇:Java EE.Servlet.生成响应


下一篇:Java EE.Servlet.处理请求