本文概述
- 什么是Docker套接字?
- 停止Docker
- 编辑docker.conf和docker.socket
- 启动Docker
什么是Docker套接字?Docker套接字文件位于/var/run/docker.sock
默认情况下, 它用于与主docker守护程序(进程)进行通信。它是Docker API的入口点。默认情况下, Docker CLI使用此套接字执行docker命令。
让我向你展示如何更改docker sock文件的位置。
停止Docker首先, 如果你的系统上正在运行docker服务, 请停止它。要确认它已停止, 请运行status命令。
[email
protected]:~$ sudo service docker stop[email
protected]:~$ sudo service docker status● docker.service - Docker Application Container EngineLoaded: loaded (/lib/systemd/system/docker.service;
enabled;
vendor preset: enabled)Active: inactive (dead) since Sat 2019-11-23 15:37:00 EST;
4s agoDocs: https://docs.docker.comProcess: 1474 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=0/SUCCESS)Main PID: 1474 (code=exited, status=0/SUCCESS)Nov 10 01:56:49 geekflare dockerd[1474]: time="2019-11-10T01:56:49-05:00" level=error msg="2019/11/10 06:56:49 Entering go-plugins-helperNov 10 01:56:49 geekflare dockerd[1474]: time="2019-11-10T01:56:49-05:00" level=error msg="time=\"2019-11-10T06:56:49Z\" level=debug msg=Nov 10 01:56:49 geekflare dockerd[1474]: time="2019-11-10T01:56:49-05:00" level=error msg="time=\"2019-11-10T06:56:49Z\" level=error msg=Nov 10 01:57:23 geekflare dockerd[1474]: time="2019-11-10T01:57:23.635519865-05:00" level=info msg="Container 3141793b98f315dc90a57d81006Nov 10 01:57:24 geekflare dockerd[1474]: time="2019-11-10T01:57:24.091797103-05:00" level=info msg="ignoring event" module=libcontainerdNov 23 15:36:56 geekflare systemd[1]: Stopping Docker Application Container Engine...Nov 23 15:36:56 geekflare dockerd[1474]: time="2019-11-23T15:36:56.992795411-05:00" level=info msg="Processing signal 'terminated'"Nov 23 15:36:58 geekflare dockerd[1474]: time="2019-11-23T15:36:58.234014533-05:00" level=info msg="ignoring event" module=libcontainerdNov 23 15:37:00 geekflare dockerd[1474]: time="2019-11-23T15:37:00.403572098-05:00" level=info msg="ignoring event" module=libcontainerdNov 23 15:37:00 geekflare systemd[1]: Stopped Docker Application Container Engine.
编辑docker.conf和docker.socket以下, 我将路径从/var/run/docker.sock更改为/home/geekflare/docker.sock
- 使用新位置编辑/ etc / init /目录中的docker.conf文件。你只需要用DOCKER_SOCKET路径编辑一行即可。
[email
protected]:~$ sudo gedit /etc/init/docker.confdescription "Docker daemon"start on (filesystem and net-device-up IFACE!=lo)stop on runlevel [!2345]limit nofile 524288 1048576# Having non-zero limits causes performance problems due to accounting overhead# in the kernel. We recommend using cgroups to do container-local accounting.limit nproc unlimited unlimitedrespawnkill timeout 20pre-start script# see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mountif grep -v '^#' /etc/fstab | grep -q cgroup \|| [ ! -e /proc/cgroups ] \|| [ ! -d /sys/fs/cgroup ];
thenexit 0fiif ! mountpoint -q /sys/fs/cgroup;
thenmount -t tmpfs -o uid=0, gid=0, mode=0755 cgroup /sys/fs/cgroupfi(cd /sys/fs/cgroupfor sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups);
domkdir -p $sysif ! mountpoint -q $sys;
thenif ! mount -n -t cgroup -o $sys cgroup $sys;
thenrmdir $sys || truefifidone)end scriptscript# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)DOCKERD=/usr/bin/dockerdDOCKER_OPTS=if [ -f /etc/default/$UPSTART_JOB ];
then. /etc/default/$UPSTART_JOBfiexec "$DOCKERD" $DOCKER_OPTS --raw-logsend script# Don't emit "started" event until docker.sock is ready.# See https://github.com/docker/docker/issues/6647post-start scriptDOCKER_OPTS=DOCKER_SOCKET=if [ -f /etc/default/$UPSTART_JOB ];
then. /etc/default/$UPSTART_JOBfiif ! printf "%s" "$DOCKER_OPTS" | grep -qE -e '-H|--host';
thenDOCKER_SOCKET=/home/geekflare/docker.sockelseDOCKER_SOCKET=$(printf "%s" "$DOCKER_OPTS" | grep -oP -e '(-H|--host)\W*unix://\K(\S+)' | sed 1q)fiif [ -n "$DOCKER_SOCKET" ];
thenwhile ! [ -e "$DOCKER_SOCKET" ];
doinitctl status $UPSTART_JOB | grep -qE "(stop|respawn)/" &
&
exit 1echo "Waiting for $DOCKER_SOCKET"sleep 0.1doneecho "$DOCKER_SOCKET is up"fiend script
- 使用更新的docker.sock文件位置编辑位于/ lib / systemd / system /的docker.socket文件。
[email
protected]:~$ sudo gedit /lib/systemd/system/docker.socket[Unit]Description=Docker Socket for the APIPartOf=docker.service[Socket]ListenStream=/home/geekflare/docker.sockSocketMode=0660SocketUser=rootSocketGroup=docker[Install]WantedBy=sockets.target
【如何更改Docker sock文件的位置()】运行以下命令以更新更改(docker sock文件的位置)。
[email
protected]:~$ sudo systemctl daemon-reload
启动Docker让我们启动docker服务, 并检查其状态。你会在终端上打印的状态日志的结尾看到, 将提供docker.sock文件的更新路径。
[email
protected]:~$ sudo service docker start[email
protected]:~$ sudo service docker statusdocker.service - Docker Application Container EngineLoaded: loaded (/lib/systemd/system/docker.service;
enabled;
vendor preset: enabled)Active: active (running) since Sat 2019-11-23 15:39:36 EST;
3s agoDocs: https://docs.docker.comMain PID: 8840 (dockerd)Tasks: 17Memory: 47.6MCGroup: /system.slice/docker.service└─8840 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sockNov 23 15:39:35 geekflare dockerd[8840]: time="2019-11-23T15:39:35.091941184-05:00" level=warning msg="Your kernel does not support cgroup rt runtime"Nov 23 15:39:35 geekflare dockerd[8840]: time="2019-11-23T15:39:35.093149218-05:00" level=info msg="Loading containers: start."Nov 23 15:39:35 geekflare dockerd[8840]: time="2019-11-23T15:39:35.957842188-05:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. DaemonNov 23 15:39:36 geekflare dockerd[8840]: time="2019-11-23T15:39:36.078753190-05:00" level=info msg="Loading containers: done."Nov 23 15:39:36 geekflare dockerd[8840]: time="2019-11-23T15:39:36.664727326-05:00" level=info msg="Docker daemon" commit=481bc77 graphdriver(s)=overlay2 version=18.09.6Nov 23 15:39:36 geekflare dockerd[8840]: time="2019-11-23T15:39:36.817929464-05:00" level=error msg="cluster exited with error: error while loading TLS certificate in /var/lib/doNov 23 15:39:36 geekflare dockerd[8840]: time="2019-11-23T15:39:36.820439024-05:00" level=error msg="swarm component could not be started" error="error while loading TLS certificNov 23 15:39:36 geekflare dockerd[8840]: time="2019-11-23T15:39:36.820821712-05:00" level=info msg="Daemon has completed initialization"Nov 23 15:39:36 geekflare systemd[1]: Started Docker Application Container Engine.Nov 23 15:39:36 geekflare dockerd[8840]: time="2019-11-23T15:39:36.883382952-05:00" level=info msg="API listen on /home/geekflare/docker.sock"
在docker.sock文件的路径上运行ls命令, 只是为了确认启动docker服务时已创建此文件。
[email
protected]:~$ ls -ltotal 466832-rw-r--r-- 1 geekflare geekflare 0 Oct 23 05:32 ]drwxr-xr-x 9 tomcat tomcat 4096 Nov 18 14:30 apache-tomcat-9.0.27-rw-r--r-- 1 geekflare geekflare 10982406 Oct 7 06:21 apache-tomcat-9.0.27.tar.gzdrwxr-xr-x 8 geekflare geekflare 4096 Oct 23 06:05 chef-repo-rw-r--r-- 1 geekflare geekflare 252269838 Jul 1 15:16 chef-server-core_13.0.17-1_amd64.deb-rw-r--r-- 1 geekflare geekflare 129713682 Dec 27 2018 chef-workstation_0.2.43-1_amd64.debdrwxr-xr-x 2 geekflare geekflare 4096 Oct 23 2018 Desktop-rw-r--r-- 1 geekflare geekflare 726 Jul 27 15:10 Dockerfilesrw-rw---- 1 root docker 0 Nov 23 15:39 docker.sockdrwxr-xr-x 2 geekflare geekflare 4096 Oct 23 2018 Documentsdrwxr-xr-x 2 geekflare geekflare 4096 Jul 20 18:20 Downloads-rw-r--r-- 1 geekflare geekflare 8980 Oct 23 2018 examples.desktop
你已成功更新docker sock文件的位置。
如果你想学习Docker但又很忙, 请查看此速成班。
推荐阅读
- Windows上面搭建FlutterAndroid运行环境
- 如何在CentOS/RHEL上构建和安装最新的cURL版本()
- 如何在Ubuntu 18上安装Kubernetes()
- 9种针对中型企业的最佳数据备份解决方案
- 如何在RHEL/CentOS 8上安装最新的MongoDB()
- 如何在Ubuntu和CentOS上安装pfSense防火墙()
- 被称为Sysadmin和Developer的10个Linux发行版
- 了解网站和应用程序的真实用户监视
- 如何在Linux上使用find命令(包含40个示例)