File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -560,8 +560,12 @@ resource "docker_container" "workspace" {
560560 read_only = false
561561 }
562562
563+ # Stash the host socket outside /run, which systemd remounts as a fresh
564+ # tmpfs at boot and would shadow a bind mount placed there. A systemd
565+ # .mount unit in the image re-binds /host-docker.sock onto
566+ # /var/run/docker.sock after /run is set up.
563567 volumes {
564- container_path = " /var/run/ docker.sock"
568+ container_path = " /host- docker.sock"
565569 host_path = " /var/run/docker.sock"
566570 read_only = false
567571 }
Original file line number Diff line number Diff line change @@ -128,10 +128,12 @@ RUN printf '\nif [ -d /etc/profile.d ]; then\n for i in /etc/profile.d/*.sh; do
128128RUN mkdir -p /etc/coder
129129COPY src/base/coder-agent.service /etc/systemd/system/coder-agent.service
130130COPY src/base/web-shell.service /etc/systemd/system/web-shell.service
131+ COPY src/base/var-run-docker.sock.mount /etc/systemd/system/var-run-docker.sock.mount
132+ COPY src/base/docker-sock.tmpfiles.conf /etc/tmpfiles.d/docker-sock.conf
131133COPY --chmod=0755 src/base/web-shell-launch.sh /usr/local/bin/web-shell-launch
132134RUN install -m 0644 /dev/null /var/log/web-shell.log && \
133135 chown coder:coder /var/log/web-shell.log && \
134- systemctl enable coder-agent.service web-shell.service
136+ systemctl enable coder-agent.service web-shell.service var-run-docker.sock.mount
135137
136138# Entrypoint claims fresh-volume mountpoints for the workspace user before
137139# systemd starts. See entrypoint.sh for rationale.
Original file line number Diff line number Diff line change 11[Unit]
22Description =Coder Agent
3- After =network-online.target
3+ After =network-online.target var-run-docker.sock.mount
44Wants =network-online.target
5+ Requires =var-run-docker.sock.mount
56ConditionPathExists =/etc/coder/agent-init.sh
67
78[Service]
Original file line number Diff line number Diff line change 1+ f /var/run/docker.sock 0660 root docker -
Original file line number Diff line number Diff line change 2626# DooD: align the in-image `docker` group GID with the host socket's GID so
2727# the workspace user (member of `docker` in the image) can talk to the
2828# bind-mounted host daemon without a chmod 666 on the socket.
29- if [ -S /var/run/ docker.sock ]; then
30- sock_gid=$( stat -c ' %g' /var/run/ docker.sock)
29+ if [ -S /host- docker.sock ]; then
30+ sock_gid=$( stat -c ' %g' /host- docker.sock)
3131 cur_gid=$( getent group docker | cut -d: -f3 || true)
3232 if [ -n " $sock_gid " ] && [ " $sock_gid " != " $cur_gid " ]; then
3333 # If another group already owns the target GID, rename it out of the way
Original file line number Diff line number Diff line change 1+ [Unit]
2+ Description =Bind-mount host Docker socket into /var/run
3+ DefaultDependencies =no
4+ After =systemd-tmpfiles-setup.service
5+ Requires =systemd-tmpfiles-setup.service
6+ ConditionPathExists =/host-docker.sock
7+ Before =sysinit.target shutdown.target
8+ Conflicts =shutdown.target
9+
10+ [Mount]
11+ What =/host-docker.sock
12+ Where =/var/run/docker.sock
13+ Type =none
14+ Options =bind
15+
16+ [Install]
17+ WantedBy =sysinit.target
Original file line number Diff line number Diff line change 11[Unit]
22Description =web-shell
3- After =network-online.target
3+ After =network-online.target var-run-docker.sock.mount
44Wants =network-online.target
5+ Requires =var-run-docker.sock.mount
56
67[Service]
78Type =simple
You can’t perform that action at this time.
0 commit comments