Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mita 可以使用 docker 部署吗 #165

Open
JuTemp opened this issue Oct 11, 2024 · 3 comments
Open

mita 可以使用 docker 部署吗 #165

JuTemp opened this issue Oct 11, 2024 · 3 comments
Labels
question General or technical questions

Comments

@JuTemp
Copy link

JuTemp commented Oct 11, 2024

我想使用docker 部署mita
README没有给docker镜像地址
hub.docker.com上也没有
我试图自己编译项目 但是无法运行
我想在Alpine上运行mita

容器内没有systemctl 也没有办法使用mita用户登陆

/app/mieru # GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GOCC=musl-gcc go build -ldflags="-s -w" -o release/linux/amd64/mita cmd/mita/mita.go
/app # addgroup mita
/app # addgroup root mita
/app # ./mita run
2024-10-11T15:10:44Z FATAL update server unix domain socket permission failed: getGid("mita") failed: user: unknown user mita
2024-10-11T15:10:44Z FATAL update server unix domain socket permission failed: getGid("mita") failed: user: unknown user mita
@enfein enfein added the question General or technical questions label Oct 11, 2024
@enfein
Copy link
Owner

enfein commented Oct 11, 2024

可以。

如果在外面编译好 mita 然后复制进容器,请参考下面的命令添加用户名和用户组。

RUN /usr/sbin/useradd --no-create-home --user-group mita && mkdir -p /etc/mita

如果在容器里面编译,建议使用 golang 容器编译 mita 然后再复制到下一个容器里面,并且添加用户名和用户组。

@JuTemp
Copy link
Author

JuTemp commented Oct 12, 2024

谢谢作者的回复 我把我的实现过程写下来 可以给别人看看

先把本项目git clone下来 进入文件夹内
根据Makefile文件 编译项目 只需要mita二进制文件就行
因为我运行在Alpine容器内 所有我添加里一个环境变量 GOCC=musl-gcc
也就是

GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GOCC=musl-gcc go build -ldflags="-s -w" -o mita-musl cmd/mita/mita.go

然后将这个二进制文件放进Alpine容器内

Dockerfile:

FROM alpine

COPY ./mita-musl /app/mita
COPY ./run.sh /app/run.sh

RUN chmod +x /app/run.sh && adduser -H -D -g "" mita && mkdir -p /etc/mita

WORKDIR /app

CMD [ "sh", "/app/run.sh" ]

run.sh:

set -e

./mita run &
sleep 2

./mita apply config ./mita.json
./mita start

wait -n

docker-compose.yml:

services:
  mita:
    image: mita
    ports:
      - 40000:40000
      - 41000:41000/udp
    volumes:
      - ./mita.json:/app/mita.json

mita.json:

{
    "loggingLevel": "INFO",
    "portBindings": [
        {
            "port": 40000,
            "protocol": "TCP"
        },
        {
            "port": 41000,
            "protocol": "UDP"
        }
    ],
    "users": [
        {
            "name": "username",
            "password": "password"
        }
    ]
}

修改mita.json 然后docker compose up -d就能用了

NekoBoxForAndroid 使用v3.6.0的mieru插件 而不是v2.2.0
mieru-3.6.0

@mxyhi
Copy link
Contributor

mxyhi commented Oct 26, 2024

  • dockerfile
FROM golang:alpine AS builder

RUN apk update && apk add --no-cache git

RUN git clone https://github.com/enfein/mieru.git /build

WORKDIR /build

RUN go mod tidy

RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 GOCC=musl-gcc go build -ldflags="-s -w" -o mita cmd/mita/mita.go


FROM alpine AS base

COPY --from=builder /build/mita /usr/local/bin/

WORKDIR /app

COPY . .

RUN chmod +x ./start.sh && adduser -H -D -g "" mita && mkdir -p /etc/mita

CMD ["./start.sh"]
  • start.sh
#!/bin/sh

set -e

mita run &
sleep 2

mita apply config ./conf/config.json

mita start

mita describe config

wait -n

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question General or technical questions
Projects
None yet
Development

No branches or pull requests

3 participants