wrfly / container-web-tty

Connect your containers via a web-tty
https://container-web-tty.kfd.me/
Apache License 2.0
245 stars 45 forks source link

Modified client to use environment variables #68

Closed whatever4711 closed 2 years ago

whatever4711 commented 2 years ago

Modified the go docker client in container/docker/docker.go to call client.NewClientWithOpts(client.FromEnv), which enables the go client to connect to docker with the environment variables of the system.

With this modification a TLS connection to the docker daemon is possible and there is no need to mount docker.sock anymore.

For example, you may now run the following compose file, where a web-tty is attached to a docker-in-docker container.

networks:
  dind:

volumes:
  docker-certs-ca:
  docker-certs-client:

services:
  daemon:
    image: docker:dind
    privileged: true
    environment:
      - DOCKER_TLS_CERTDIR=/certs
    volumes:
      - docker-certs-ca:/certs/ca
      - docker-certs-client:/certs/client
    networks:
      dind:
        aliases:
          - docker

  web-tty:
    image: wrfly/container-web-tty:latest
    depends_on:
      - daemon
    ports:
      - 8080:8080
    networks:
      - dind
    environment:
      - WEB_TTY_DEBUG=false
      - DOCKER_TLS_VERIFY=1
      - DOCKER_TLS_CERTDIR=/certs
      - DOCKER_CERT_PATH=/certs/client
      - DOCKER_HOST=tcp://docker:2376
    volumes:
      - docker-certs-client:/certs/client:ro
wrfly commented 2 years ago

Hi @whatever4711 , great job! BTW can u help to delete the commented lines? so that I can merge it directly, thanks!

whatever4711 commented 2 years ago

Hi @wrfly, I removed the uncommented lines. Additionally, I checked if !strings.HasPrefix(host, "tcp://") such that tcp:// is only added if it is needed. Best regards

wrfly commented 2 years ago

great, thanks!