Docker image support

1. Add build docker image in makefile
2. Add use with docker in readme
This commit is contained in:
lucheng
2024-05-07 14:54:38 +08:00
parent d82840fa4a
commit 903227b49d
3 changed files with 41 additions and 0 deletions

26
Dockerfile Normal file
View File

@@ -0,0 +1,26 @@
FROM golang:1.20 as builder
ARG TARGETOS
ARG TARGETARCH
ENV GOPROXY=https://goproxy.io,direct
WORKDIR /
COPY go.mod go.mod
COPY go.sum go.sum
COPY pkg pkg
COPY main.go main.go
RUN CGO_ENABLED=1 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o virtuallan main.go
FROM alpine:3.19
WORKDIR /
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
RUN apk add --no-cache gcompat
COPY config config
COPY static static
COPY --from=builder virtuallan virtuallan
CMD /virtuallan server -d /config

View File

@@ -1,4 +1,6 @@
.DEFAULT_GOAL := build
IMG ?= virtuallan:latest
CONTAINER_TOOL ?= docker
.PHONY: gen
gen:
@@ -11,3 +13,7 @@ build: gen
.PHONY: clean
clean:
rm -rf virtuallan
.PHONY: build-docker
build-docker: gen
$(CONTAINER_TOOL) build -t ${IMG} .

View File

@@ -27,6 +27,14 @@ go build -o virtuallan main.go
go generate will generate an random aes key
## Use with docker
**Build**
>IMG=\<your image name>:\<tag> make build-docker
**Run docker image as server**
>docker run --privileged=true -d --restart always -p 6123:6123/udp -p 8000:8000 quay.io/shawnlu0127/virtuallan:20240507
## Getting started
**Server**
@@ -88,6 +96,7 @@ OPTIONS:
### Try it out
If enable web, it will start a http server on port 8000. Check the endpoints in index page.
![monitor](./docs/statics/endpoints.png)
Links of virtuallan server