Code Monkey home page Code Monkey logo

Comments (3)

cblomart avatar cblomart commented on July 22, 2024 1

Thanks, a good explanation is better than any elucubrations

from caddy-docker-proxy.

cblomart avatar cblomart commented on July 22, 2024

Look like labels of services are parsed and not label of containers in the service descriptions.

So in in generator.go:154 the service.Spec.Labels refers to labels of the service

func addServiceToCaddyFile(buffer *bytes.Buffer, service *swarm.Service) {
    directives, err := parseDirectives(service.Spec.Labels, service, func() (string, error) {

Considering a compose file as follows (with swarmpit as an example):

version: '3'

services:
  app:
    image: swarmpit/swarmpit:latest
    environment:
      - SWARMPIT_DB=http://db:5984
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - swarmpit
      - caddy
    labels:
      caddy_1.address: docker.lan:80
      caddy_1.targetport: "8080"
      caddy_1.tls: "off"
    deploy:
      placement:
        constraints:
          - node.role == manager

  db:
    image: klaemo/couchdb:2.0.0
    volumes:
      - /var/volumes/swarmpit:/opt/couchdb/data
    networks:
      - swarmpit

  agent:
    image: swarmpit/agent:latest
    environment:
      - DOCKER_API_VERSION=1.35
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - swarmpit
    deploy:
      mode: global

networks:
  swarmpit:
    driver: overlay
  caddy:
    external: true

To find labels back, the container spec labels should be parsed so relace generator.go:155

func addServiceToCaddyFile(buffer *bytes.Buffer, service *swarm.Service) {
    directives, err := parseDirectives(service.Spec.TaskTemplate.ContainerSpec.Labels, service, func() (string, error) {

Maybe you could also skip parsing a container if it has a "com.docker.swarm.service.*" label.
That is considering that tags should be declared at the service level

from caddy-docker-proxy.

lucaslorentz avatar lucaslorentz commented on July 22, 2024

Some users doesn't use docker services, therefore reading labels from containers and proxying to container IP is useful to some people. But we don't support proxying into multiple containers yet.

I don't think they're redundant, they're complementary.

The recommended approach is to proxy to docker service, not to containers. That means your labels should on your service service, not container. Therefore you must put your labels the deploy section. According to docs: https://docs.docker.com/compose/compose-file/#labels-1

services:
  app:
    image: swarmpit/swarmpit:latest
    environment:
      - SWARMPIT_DB=http://db:5984
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - swarmpit
      - caddy
    deploy:
      labels:
        caddy_1.address: docker.lan:80
        caddy_1.targetport: "8080"
        caddy_1.tls: "off"
      placement:
        constraints:
          - node.role == manager

I don't have any problems with that setup, I run a caddy docker service with 1 or 2 instances at manager nodes, and those instances proxies to every service that I have on my swarm cluster.

Can you please try that?

from caddy-docker-proxy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.