Docker 양말 파일 위치를 변경하는 방법은 무엇입니까?

docker.sock 파일 경로를 변경하는 방법이 궁금하십니까?

도커 소켓이란 무엇입니까?

Docker 소켓 파일은 /var/run/docker.sock에 있습니다.

기본적으로 기본 도커 데몬(프로세스)과 통신하는 데 사용됩니다. Docker API의 진입점입니다. 이 소켓은 기본적으로 Docker CLI에서 docker 명령을 실행하는 데 사용됩니다.

docker sock 파일의 위치를 ​​변경하는 방법을 알려드리겠습니다.

도커 중지

먼저 도커 서비스가 시스템에서 실행 중이면 중지하십시오. 중지되었는지 확인하려면 status 명령을 실행합니다.

[email protected]:~$ sudo service docker stop
[email protected]:~$ sudo service docker status
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sat 2019-11-23 15:37:00 EST; 4s ago
Docs: https://docs.docker.com
Process: 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 koreantech.org dockerd[1474]: time="2019-11-10T01:56:49-05:00" level=error msg="2019/11/10 06:56:49 Entering go-plugins-helper
Nov 10 01:56:49 koreantech.org 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 koreantech.org 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 koreantech.org dockerd[1474]: time="2019-11-10T01:57:23.635519865-05:00" level=info msg="Container 3141793b98f315dc90a57d81006
Nov 10 01:57:24 koreantech.org dockerd[1474]: time="2019-11-10T01:57:24.091797103-05:00" level=info msg="ignoring event" module=libcontainerd
Nov 23 15:36:56 koreantech.org systemd[1]: Stopping Docker Application Container Engine...
Nov 23 15:36:56 koreantech.org dockerd[1474]: time="2019-11-23T15:36:56.992795411-05:00" level=info msg="Processing signal 'terminated'"
Nov 23 15:36:58 koreantech.org dockerd[1474]: time="2019-11-23T15:36:58.234014533-05:00" level=info msg="ignoring event" module=libcontainerd
Nov 23 15:37:00 koreantech.org dockerd[1474]: time="2019-11-23T15:37:00.403572098-05:00" level=info msg="ignoring event" module=libcontainerd
Nov 23 15:37:00 koreantech.org systemd[1]: Stopped Docker Application Container Engine.

docker.conf 및 docker.socket 편집

다음은 경로를 /var/run/docker.sock에서 /home/koreantech.org/docker.sock으로 변경합니다.

  • /etc/init/ 디렉토리 내의 docker.conf 파일을 새 위치로 편집하십시오. DOCKER_SOCKET 경로로 한 줄만 편집하면 됩니다.
[email protected]:~$ sudo gedit /etc/init/docker.conf

description "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 unlimited

respawn

kill timeout 20

pre-start script
# see also https://github.com/tianon/cgroupfs-mount/blob/master/cgroupfs-mount
if grep -v '^#' /etc/fstab | grep -q cgroup 
|| [ ! -e /proc/cgroups ] 
|| [ ! -d /sys/fs/cgroup ]; then
exit 0
fi
if ! mountpoint -q /sys/fs/cgroup; then
mount -t tmpfs -o uid=0,gid=0,mode=0755 cgroup /sys/fs/cgroup
fi
(
cd /sys/fs/cgroup
for sys in $(awk '!/^#/ { if ($4 == 1) print $1 }' /proc/cgroups); do
mkdir -p $sys
if ! mountpoint -q $sys; then
if ! mount -n -t cgroup -o $sys cgroup $sys; then
rmdir $sys || true
fi
fi
done
)
end script

script
# modify these in /etc/default/$UPSTART_JOB (/etc/default/docker)
DOCKERD=/usr/bin/dockerd
DOCKER_OPTS=
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi
exec "$DOCKERD" $DOCKER_OPTS --raw-logs
end script

# Don't emit "started" event until docker.sock is ready.
# See https://github.com/docker/docker/issues/6647
post-start script
DOCKER_OPTS=
DOCKER_SOCKET=
if [ -f /etc/default/$UPSTART_JOB ]; then
. /etc/default/$UPSTART_JOB
fi

if ! printf "%s" "$DOCKER_OPTS" | grep -qE -e '-H|--host'; then
<strong>DOCKER_SOCKET=/home/koreantech.org/docker.sock
</strong>else
DOCKER_SOCKET=$(printf "%s" "$DOCKER_OPTS" | grep -oP -e '(-H|--host)W*unix://K(S+)' | sed 1q)
fi

if [ -n "$DOCKER_SOCKET" ]; then
while ! [ -e "$DOCKER_SOCKET" ]; do
initctl status $UPSTART_JOB | grep -qE "(stop|respawn)/" && exit 1
echo "Waiting for $DOCKER_SOCKET"
sleep 0.1
done
echo "$DOCKER_SOCKET is up"
fi
end script
  • 업데이트된 docker.sock 파일 위치로 /lib/systemd/system/에 있는 docker.socket 파일을 편집합니다.
[email protected]:~$ sudo gedit /lib/systemd/system/docker.socket

[Unit]

Description=Docker Socket for the API

PartOf=docker.service

[Socket]

<strong>ListenStream=/home/koreantech.org/docker.sock
</strong>
SocketMode=0660

SocketUser=root

SocketGroup=docker

[Install]

WantedBy=sockets.target

아래 명령을 실행하여 변경 사항(도커 sock 파일의 위치)을 업데이트합니다.

[email protected]:~$ sudo systemctl daemon-reload

도커 시작

도커 서비스를 시작하고 시작되었는지 상태를 확인해보자. 터미널에 인쇄된 상태 로그 끝에 docker.sock 파일의 업데이트된 경로가 표시됩니다.

[email protected]:~$ sudo service docker start
[email protected]:~$ sudo service docker status

docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-11-23 15:39:36 EST; 3s ago
Docs: https://docs.docker.com
Main PID: 8840 (dockerd)
Tasks: 17
Memory: 47.6M
CGroup: /system.slice/docker.service
└─8840 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Nov 23 15:39:35 koreantech.org 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 koreantech.org dockerd[8840]: time="2019-11-23T15:39:35.093149218-05:00" level=info msg="Loading containers: start."
Nov 23 15:39:35 koreantech.org 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. Daemon
Nov 23 15:39:36 koreantech.org dockerd[8840]: time="2019-11-23T15:39:36.078753190-05:00" level=info msg="Loading containers: done."
Nov 23 15:39:36 koreantech.org dockerd[8840]: time="2019-11-23T15:39:36.664727326-05:00" level=info msg="Docker daemon" commit=481bc77 graphdriver(s)=overlay2 version=18.09.6
Nov 23 15:39:36 koreantech.org 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/do
Nov 23 15:39:36 koreantech.org 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 certific
Nov 23 15:39:36 koreantech.org dockerd[8840]: time="2019-11-23T15:39:36.820821712-05:00" level=info msg="Daemon has completed initialization"
Nov 23 15:39:36 koreantech.org systemd[1]: Started Docker Application Container Engine.
Nov 23 15:39:36 koreantech.org dockerd[8840]: time="2019-11-23T15:39:36.883382952-05:00" level=info msg="API listen on <strong>/home/koreantech.org/docker.sock</strong>"

docker.sock 파일의 경로에서 ls 명령을 실행하여 도커 서비스를 시작할 때 이 파일이 생성되었는지 확인합니다.

[email protected]:~$ ls -l
total 466832
-rw-r--r-- 1 koreantech.org koreantech.org 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 koreantech.org koreantech.org 10982406 Oct 7 06:21 apache-tomcat-9.0.27.tar.gz
drwxr-xr-x 8 koreantech.org koreantech.org 4096 Oct 23 06:05 chef-repo
-rw-r--r-- 1 koreantech.org koreantech.org 252269838 Jul 1 15:16 chef-server-core_13.0.17-1_amd64.deb
-rw-r--r-- 1 koreantech.org koreantech.org 129713682 Dec 27 2018 chef-workstation_0.2.43-1_amd64.deb
drwxr-xr-x 2 koreantech.org koreantech.org 4096 Oct 23 2018 Desktop
-rw-r--r-- 1 koreantech.org koreantech.org 726 Jul 27 15:10 Dockerfile
srw-rw---- 1 root docker 0 Nov 23 15:39 <strong>docker.sock</strong>
drwxr-xr-x 2 koreantech.org koreantech.org 4096 Oct 23 2018 Documents
drwxr-xr-x 2 koreantech.org koreantech.org 4096 Jul 20 18:20 Downloads
-rw-r--r-- 1 koreantech.org koreantech.org 8980 Oct 23 2018 examples.desktop

docker sock 파일의 위치를 ​​성공적으로 업데이트했습니다.

Docker를 배우고 싶지만 바쁘다면 이것을 확인하십시오. 단기 특강.

기사를 재미있게 읽었습니까? 세상과 함께 나누는 건 어떨까요?