centos 安装 docker
https://docs.docker.com/engine/installation/linux/centos/
前期准备:需要64位操作系统,3.10版本以上内核。
$ uname -r
3.10.0-229.el7.x86_64
安装docker 引擎
通过 yum 安装
- 通过 root 登录
- 系统更新
$ sudo yum update
- 添加 repo 源
$ sudo tee /etc/yum.repos.d/docker.repo <<-'EOF'
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
- 安装 docker 包
$ sudo yum install docker-engine
- 启用服务
$ sudo systemctl enable docker.service
- 启动守护进程
$ sudo systemctl start docker
测试是否安装成功
$ sudo docker run --rm hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c04b14da8d14: Pull complete Digest: sha256:0256e8a36e2070f7bf2d0b0763dbabdd67798512411de4cdcf9431a1feb60fd9 Status: Downloaded newer image for hello-world:latest 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. 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 Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/engine/userguide/
使用脚本安装
- 通过 root 登录
系统更新
$ sudo yum update
运行docker 安装脚本
$ curl -fsSL https://get.docker.com/ | sh
启用服务
$ sudo systemctl enable docker.service
启动守护进程
$ sudo systemctl start docker
测试是否安装成功
$ sudo docker run --rm hello-world
创建 docker 组
为了启动 daemon 而不使用root
- root 权限
创建 docker 组
$ sudo groupadd docker groupadd:“docker”组已存在
在 docker组添加用户
此处先使用 useradd 、passwd 添加用户,设置密码 $ sudo usermod -aG docker your_username
退出并且登录到your_username,如果在your_username下也建议退出再重新登录一次,这确保您的用户正在运行正确的权限。
- 验证运行docker已不再需要sudo命令
$ docker run --rm hello-world
开机启动 docker daemon
$ sudo systemctl enable docker
删除 docker (使用yum)
列出已安装的 docker 包
$ yum list installed | grep docker docker-engine.x86_64 1.12.3-1.el7.centos @dockerrepo docker-engine-selinux.noarch 1.12.3-1.el7.centos @dockerrepo
删除上面的包
$ sudo yum -y remove docker-engine.x86_64 $ sudo yum -y remove docker-engine-selinux.noarch *This command does not remove images, containers, volumes, or user-created configuration files on your host.*
remove images, containers, volumes
$ rm -rf /var/lib/docker
Locate and delete any user-created configuration files.