给短链系统收个尾,写个dockerfile,本来就很害怕写这个东西
然后这个东西一写就是半天过去了
而且基本上就是在蒙蔽状态下度过的
代码写写很快,但是没啥用
Dockerfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| FROM golang:1.21 as builder ENV GOPROXY https://goproxy.cn,direct
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -a -installsuffix cgo -o main .
FROM alpine:3.12 WORKDIR /app
COPY --from=builder /app/main /app/main
EXPOSE 8080
CMD ["/app/main"]
|
RUN CGO_ENABLED=0
如果没有静态编译
就会找不到/app/main
真特么恶心,搞了我半个下午加一个晚上
Docker-Compose.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| version: '3.1'
services: app: build: . container_name: short-url-app ports: - "8080:8080" depends_on: - mysql restart: always healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080"] interval: 5s timeout: 10s retries: 3
mysql: image: mysql:latest container_name: short-url-mysql environment: MYSQL_ROOT_PASSWORD: password MYSQL_DATABASE: shortURL MYSQL_PASSWORD: password MYSQL_USER: user ports: - "3307:3306" restart: always
|
其实也很简单
Config
1 2 3 4 5 6 7 8 9 10 11 12 13
| mysql: userName: user password: password host: 127.0.0.1 port: 3307 dbName: shortURL
|
应用程序的Config,其实没啥用
就是想说容器内的网络是怎么样的
同时mysql类似于DNS域名
收获
还会写了一点命令行
进入交互式
1
| docker run -it <image_id> /bin/sh
|
当前目录
目录下文件
感谢NX,老板,天工AI