非root用户管理docker
usermod -aG docker $USER
[root@linux-node2 ~]# useradd docker_user1
[root@linux-node2 ~]# su - docker_user1
[docker_user1@linux-node2 ~]$ docker run hello-world
docker: Got permission denied while trying to connect to the Docker daemon socket a///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.38/containers/creal unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
[docker_user1@linux-node2 ~]$ logout
[root@linux-node2 ~]# usermod -aG docker docker_user1
[root@linux-node2 ~]# id docker_user1
uid=1000(docker_user1) gid=1000(docker_user1) groups=1000(docker_user1),993(docker)
[root@linux-node2 ~]# su - docker_user1
Last login: Wed Oct 31 13:01:34 CST 2018 on pts/0
[docker_user1@linux-node2 ~]$ 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://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
如果docker run hello-world报错如下:
#报错
WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
#解决办法
chown "$USER":"$USER" /home/"$USER"/.docker -R
chmod g+rwx "$HOME/.docker" -R
docker配置远程访问
#通过daemon.json文件,配置远程访问
vim /etc/docker/daemon.json
{
"hosts": ["unix:///var/run/docker.sock", "tcp://127.0.0.1:2375"]
}
#重启docker
systemctl restart docker.service
#检查端口是否监听
netstat -lntp | grep dockerd
tcp 0 0 127.0.0.1:2375 0.0.0.0:* LISTEN 3758/dockerd
为Docker指定DNS服务器
vim /etc/docker/daemon.json
{
"dns": ["8.8.8.8", "8.8.4.4"]
}
#重启docker
systemctl restart docker.service