1. 安装docker-ce [root],ce为docker社区版,免费,ee版为企业版,收费
列出所有已安装docker
1 # rpm -qa | grep docker
删除已安装docker
1 # rpm -e rpmname
安装docker-ce
1 # yum install docker-ce.x86_64 # 此命令会自动安装相关依赖包
配置Daocloud加速
1 # curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://8ad7943c.m.daocloud.io
2. 开启dock服务,并设置开机自启 [root]
1 # systemctl start docker 2 # systemctl enable docker.service
3. 测试docker [root]
1 # 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: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. 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/
1 # docker info #此命令可以查看dock内image和container信息
4. 使特定普通用户可以执行dock命令 [root]
1 # visudo
在最下方加入此行,此行会允许特定用户以sudo方式运行docker,第一次运行时要求输入该特定用户的密码,以后每隔5分钟重复运行docker命令时需要输入密码:
1 #docker 2 username ALL=(ALL) /usr/bin/docker
下面这行的区别在于,不需要输入sudo密码,但是并不安全
1 #docker 2 username ALL=(ALL) NOPASSWD: /usr/bin/docker
设置/usr/bin/docker别名
1 # alias docker="sudo /usr/bin/docker"
直接在命令行输入上述命令时,此命令不会永久生效,如果想永久生效,将其加入对应用户的.bashrc中即可
1 vim ~/.bashrc
1 # .bashrc 2 3 # User specific aliases and functions 4 5 alias rm='rm -i' 6 alias cp='cp -i' 7 alias mv='mv -i' 8 alias docker="sudo /usr/bin/docker" 9 10 # Source global definitions 11 if [ -f /etc/bashrc ]; then 12 . /etc/bashrc 13 fi 14 ...
5. 测试 [username]
配置完上述命令之后,指定的普通用户就可以直接运行docker命令了
1 # dock info
参考自:
http://cloud.51cto.com/art/201508/488478.htm