xcaddy
xcaddy copied to clipboard
Dockerfile and docker compose
Hi i'm trying to contribute by creating Dockerfile and docker-compose
I ran into unfamiliar issue
Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "xcaddy": executable file not found in $PATH: unknown
Dockerfile
FROM alpine:3.20
# Install the necessary packages for xcaddy
RUN apk update && apk add --no-cache \
curl \
git \
go \
gcc \
musl-dev \
libc-dev \
openssl \
bash \
ca-certificates
# Install xcaddy
RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
# Verify installation
RUN /root/go/bin/xcaddy version
CMD ["xcaddy", "help"]
docker-compose.yml
xcaddy:
container_name: xcaddy
build: .
restart: unless-stopped
ports:
# temporary ports
- "180:80"
- "1443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile
- caddy_data:/data
- caddy_config:/config
- ./caddylogs:/var/log/caddy
environment:
- [email protected]
networks:
- xcaddy
volumes:
caddy_data:
caddy_config:
caddylogs:
networks:
xcaddy:
external: true```
Use our builder image instead: https://caddyserver.com/docs/build#docker
Nice to know that, I will check out it later 👍
When I use the builder image I get errors like
35.17 2024/11/06 22:02:32 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath -tags nobadger
70.81 # github.com/google/gopacket/pcap
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:30:22: undefined: pcapErrorNotActivated
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:52:17: undefined: pcapTPtr
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:64:10: undefined: pcapPkthdr
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:103:6: undefined: pcapBpfProgram
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:110:7: undefined: pcapPkthdr
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:268:33: undefined: pcapErrorActivated
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:269:33: undefined: pcapWarningPromisc
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:270:33: undefined: pcapErrorNoSuchDevice
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: undefined: pcapErrorDenied
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:748:14: undefined: pcapTPtr
70.81 /go/pkg/mod/github.com/google/[email protected]/pcap/pcap.go:271:33: too many errors
74.00 2024/11/06 22:03:10 [INFO] Skipping cleanup as requested; leaving folder intact: /tmp/buildenv_2024-11-06-2201.858105741
74.00 2024/11/06 22:03:10 [FATAL] exit status 1
34.43 2024/11/06 22:09:09 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath -tags nobadger
38.76 # runtime/cgo
38.76 cgo: C compiler "gcc" not found: exec: "gcc": executable file not found in $PATH
So I add gcc and then:
33.22 2024/11/06 22:10:35 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath -tags nobadger
37.56 # runtime/cgo
37.56 _cgo_export.c:3:10: fatal error: stdlib.h: No such file or directory
37.56 3 | #include <stdlib.h>
37.56 | ^~~~~~~~~~
37.56 compilation terminated.
Docker file looks like this:
FROM caddy:2-builder AS builder
RUN apk update && apk add gcc
RUN CGO_ENABLED=1 xcaddy build \
--with github.com/mholt/caddy-ratelimit \
--with github.com/rushiiMachine/caddy-ja3
FROM caddy:2
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
For anyone with similar problems, you can install all the deps and then it will work:
FROM caddy:2-builder AS builder
RUN apk update && apk add gcc g++ make libpcap-dev libpcap
RUN CGO_ENABLED=1 xcaddy build \
--with github.com/mholt/caddy-ratelimit \
--with github.com/rushiiMachine/caddy-ja3
FROM caddy:2
RUN apk update && apk add libpcap
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
@forgetso, in your case, the dependency github.com/rushiiMachine/caddy-ja3 has a transitive dependency that requires C, thus consequently CGO. Your final approach to install C toolchain is per expectations when CGO is involved.
I don't there's anything actionable in this issue. I'll close it, but feel free to correct my impression.
Yeah no worries, no actionable points. Was just leaving this info here for search purposes.