{"id":18526706,"url":"https://github.com/rogusdev/caddyfile-docker-gen","last_synced_at":"2025-04-23T04:19:18.816Z","repository":{"id":142081000,"uuid":"262453832","full_name":"rogusdev/caddyfile-docker-gen","owner":"rogusdev","description":"Generate Caddyfile (for Caddy 2) from Docker containers and reload caddy in its (separate) docker container","archived":false,"fork":false,"pushed_at":"2023-03-29T23:09:05.000Z","size":8,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T04:19:13.338Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rogusdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-09T00:10:02.000Z","updated_at":"2025-03-18T13:50:49.000Z","dependencies_parsed_at":"2023-07-22T19:16:47.686Z","dependency_job_id":null,"html_url":"https://github.com/rogusdev/caddyfile-docker-gen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogusdev%2Fcaddyfile-docker-gen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogusdev%2Fcaddyfile-docker-gen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogusdev%2Fcaddyfile-docker-gen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rogusdev%2Fcaddyfile-docker-gen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rogusdev","download_url":"https://codeload.github.com/rogusdev/caddyfile-docker-gen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250366715,"owners_count":21418772,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T17:52:14.767Z","updated_at":"2025-04-23T04:19:18.791Z","avatar_url":"https://github.com/rogusdev.png","language":"Python","readme":"# caddyfile-docker-gen\nGenerate Caddyfile (for Caddy 2) from Docker containers and reload caddy in its (separate) docker container\n\n\n```\n# after starting a new docker container on the server, in the correct network, with the necessary labels\n#  for now, need to rebuild caddyfile and restart caddy2\ncd ~/caddyfile-docker-gen/\nsudo chown -Rh $USER:$USER caddy_data/\ndocker-compose -f docker-compose-gen.yaml up --build -d\ncd -\n\n\ndocker rm -f caddy\ndocker run -d --restart=always -p 80:80 -p 443:443 --network=www -v ./Caddyfile:/etc/caddy/Caddyfile:ro -v ./caddy_data:/data --name caddy caddy:2.1.1-alpine\n\ndocker rm -f caddyfile-docker-gen\ndocker build -t caddyfile-docker-gen . \u0026\u0026 docker run -d --restart=always --network=www -v /var/run/docker.sock:/var/run/docker.sock:ro -v ./Caddyfile:/etc/caddy/Caddyfile -e CADDY_IMAGE=caddy -e LABEL_PREFIX=caddy -e CADDYFILE_PATH=/etc/caddy/Caddyfile --name caddyfile-docker-gen caddyfile-docker-gen\n\n\n\n# root writes the files so have to do this every time I docker-compose back up...\nsudo chown -Rh $USER:$USER caddy_data/\n\n\ndocker-compose -f docker-compose-demo.yaml up --build -d\n\nmkdir caddy_data\n\ndocker-compose up --build -d\n\ndocker-compose -f docker-compose-gen.yaml up --build -d\n\ncurl --unix-socket /var/run/docker.sock http://localhost/containers/json | jq\n\n\ndocker exec -it caddyfile-docker-gen_caddy_1 cat /etc/caddy/Caddyfile\n\ndocker exec -it caddyfile-docker-gen_caddy_1 caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile\n\n# Cannot rm the Caddyfile file, must edit it in place!\n#  https://github.com/moby/moby/issues/15793#issuecomment-135411504\n\ndocker-compose restart caddy\n\n\n\n# let caddy docker network (caddy) proxy requests to other docker webapp network (www)\n#  use docker network ls (also in ifconfig) to see the ids for each br(idge) network\n#  by default, docker compose networks are named \"{compose yaml folder}_default\"\n# https://stackoverflow.com/questions/36035595/communicating-between-docker-containers-in-different-networks-on-the-same-host/51373066#51373066\n\n\ndocker network create www\n\nWWW_BRIDGE_ID=$(docker network ls | grep www | cut -d ' ' -f 1)\nCADDY_BRIDGE_ID=$(docker network ls | grep caddy | cut -d ' ' -f 1)\n\necho \"caddy: $CADDY_BRIDGE_ID -- www: $WWW_BRIDGE_ID\"\nsudo iptables -I DOCKER-USER -i br-$CADDY_BRIDGE_ID -o br-$WWW_BRIDGE_ID -j ACCEPT\nsudo iptables -I DOCKER-USER -i br-$WWW_BRIDGE_ID -o br-$CADDY_BRIDGE_ID -j ACCEPT\nsudo iptables -L DOCKER-USER -v # to confirm\n\n\n\n\ndocker exec -it caddyfile-docker-gen_caddy_1 apk --no-cache add curl\n\ndocker exec -it caddyfile-docker-gen_caddy_1 curl http://172.19.0.2:80\n\ndocker exec -it caddyfile-docker-gen_caddy_1 curl http://172.21.0.2:5000/api/v1/hello\n\n\n\n$ curl https://localhost\ncurl: (60) SSL certificate problem: unable to get local issuer certificate\nMore details here: https://curl.haxx.se/docs/sslcerts.html\n\ncurl failed to verify the legitimacy of the server and therefore could not\nestablish a secure connection to it. To learn more about this situation and\nhow to fix it, please visit the web page mentioned above.\n\n$ curl https://whoami1.example.com\nI'm 93ba9a067d58\n$ curl https://whoami2.example.com\nI'm 430e7af4b292\n\n$ curl http://172.20.0.3:8000\nI'm 93ba9a067d58\n$ curl http://172.20.0.2:8000\nI'm 430e7af4b292\n```\n\n# Run tests\nIn fish:\n\n    docker build -t caddyfile-docker-gen . ; and docker run -it caddyfile-docker-gen -m unittest tests.app_tests\n\n\n\n    docker run --restart=always --network=caddy -u=$(id -u) -p 80:80 -p 443:443 -v ./Caddyfile:/etc/caddy/Caddyfile:ro -v ./caddy_data:/data --name caddy caddy:2.0.0-alpine\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frogusdev%2Fcaddyfile-docker-gen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frogusdev%2Fcaddyfile-docker-gen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frogusdev%2Fcaddyfile-docker-gen/lists"}