Sign inSign up

x3rax/docker-caddy-auto-connect

By x3rax

•Updated about 1 year ago

https://code.x3ro.net/x3ro/docker-caddy-auto-connect

Image
Networking
Security
Web servers
0

925

x3rax/docker-caddy-auto-connect repository overview

⁠Docker Caddy Auto-Connect

-> Source code on my Forgejo⁠

This is a companion to Caddy-Docker-Proxy⁠ that auto-connects the Caddy container to the ingress network of your web-facing containers.

This approach ensures that your app networks are segregated so apps can't reach each other but can still all be connect to the same Caddy instance.

⁠Usage

  • Define a name for your Caddy container
  • Add a network for each web-facing container that will be shared with caddy
  • Add all web-facing containers to their caddy-shared networks respectively
  • Add the label caddy_ingress_network to each web-facing container and set its value to the name of the network
  • Start caddy-auto-connect (when using the docker image⁠ make sure to mount the docker socket: /var/run/docker.sock into the container)
⁠Docker Compose Example
⁠App docker-compose.yaml
networks:
  # Create a network for the web-facing app (this network will be prefixed with
  # the docker-compose project name)
  caddy:

services:
  caddy:
    image: some/app
    networks:
      # Add the network to the web-facing container (use the name defined in
      # the `docker-compose.yaml`)
      - caddy
    labels:
      # Set the ingress network to the name of the network. If you didn't
      # define a custom network name, prefix the name with
      # `${COMPOSE_PROJECT_NAME}_`
      caddy_ingress_network: "${COMPOSE_PROJECT_NAME}_caddy"
⁠Caddy + Auto-Connect docker-compose.yaml
services:
  caddy:
    container_name: caddy # Required for caddy-auto-connect
    image: lucaslorentz/caddy-docker-proxy:ci-alpine
    # ...

  auto-connect:
    image: x2rax/docker-caddy-auto-connect
    depends_on:
      - caddy
    environment:
      CADDY_CONTAINER: "caddy"
      NETWORK_LABEL: "caddy_ingress_network"
    volumes:
      - "${DOCKER_SOCK:-/var/run/docker.sock}:/var/run/docker.sock:ro"

⁠Environment Variables

VariableDescriptionDefault value
CADDY_CONTAINERName of the caddy containercaddy
NETWORK_LABELLabel used to get the network namecaddy_ingress_network

Tag summary

Content type

Image

Digest

sha256:2f90995ae…

Size

161.3 MB

Last updated

about 1 year ago

docker pull x3rax/docker-caddy-auto-connect