Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active October 17, 2022 12:40
Show Gist options
  • Save avoidik/78bd80827c4f7e17d8fad0cef8d6d21b to your computer and use it in GitHub Desktop.
Save avoidik/78bd80827c4f7e17d8fad0cef8d6d21b to your computer and use it in GitHub Desktop.
Share Docker socket via socat

In general this action is extremely insecure (you know what are you doing, right?)

export DEV_USER=jenkins
export DEV_UID=1000
export DEV_GID=1000

socat -d -d UNIX-LISTEN:/home/"${DEV_USER}"/.docker/docker_socket,fork,user="${DEV_UID}",group="${DEV_GID}",mode=777 UNIX-CONNECT:/var/run/docker.sock

export DOCKER_HOST=unix:///home/${DEV_USER}/.docker/docker_socket
# /etc/systemd/system/docker-socat.service
[Unit]
Description=Docker socket socat
After=docker.service
Requires=docker.service

[Service]
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=docker-socat
Environment=DEV_USER=jenkins
Environment=DEV_UID=1000
Environment=DEV_GID=1000
ExecStart=socat -d -d UNIX-LISTEN:/home/${DEV_USER}/.docker/docker_socket,fork,user=${DEV_UID},group=${DEV_GID},mode=777 UNIX-CONNECT:/var/run/docker.sock
Restart=always

[Install]
WantedBy=multi-user.target
jenkins:
  environment:
    - DOCKER_HOST=tcp://socat:2375
  networks:
    - jenkins

socat:
  image: alpine/socat
  command: TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock
  volumes:
    - /var/run/docker.sock:/var/run/docker.sock
  networks:
    - jenkins

Reference docker/for-mac#4755

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment