docker在Ubuntu17.04 环境搭建

版权声明:本文为博主原创文章,可以随便转。。。。估计也没什么人需要转 https://blog.csdn.net/github_38838414/article/details/81512113

Ubuntu17.04和Ubuntu16的搭建步骤其实一样

1.换个安装源:
这里写图片描述
2.按照官网的顺序,依次输入官网提供的命令,官网地址
命令如下:
使用 APT 安装
由于 apt 源使用 HTTPS 以确保软件下载过程中不被篡改。因此,我们首先需要添加使用 HTTPS 传输的软件包以及 CA 证书。

$ sudo apt-get update
$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    software-properties-common
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository \
    "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
    $(lsb_release -cs) \
    stable"
$ sudo apt-get update
$ sudo apt-get install docker-ce

启动 Docker CE

$ sudo systemctl enable docker
$ sudo systemctl start docker

3.搭建完成,若安装时遇到什么看不懂也一下子查不到的错误,就重启一遍,再不行就重装系统(滑稽)

4.环境搭建完成后,若直接运行docker 命令会出现
”Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get http://%2Fvar%2Frun%2Fdocker.sock/v1.26/images/json: dial unix /var/run/docker.sock: connect: permission denied“的提示

原因
摘自docker mannual上的一段话

Manage Docker as a non-root user

The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can only access it using sudo. The docker daemon always runs as the root user.

If you don’t want to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
大概的意思就是:docker进程使用Unix Socket而不是TCP端口。而默认情况下,Unix socket属于root用户,需要root权限才能访问。

解决方法:

sudo groupadd docker     #添加docker用户组
sudo gpasswd -a $USER docker     #将登陆用户加入到docker用户组中
newgrp docker     #更新用户组
docker ps    #测试docker命令是否可以使用sudo正常使用

猜你喜欢

转载自blog.csdn.net/github_38838414/article/details/81512113
今日推荐