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

添加docker支持 #54

Open
Lxeon opened this issue Mar 20, 2024 · 5 comments
Open

添加docker支持 #54

Lxeon opened this issue Mar 20, 2024 · 5 comments

Comments

@Lxeon
Copy link

Lxeon commented Mar 20, 2024

Dockerfile:

FROM ubuntu:latest
ENV LANG        C.UTF-8
ENV LANGUAGE    C.UTF-8
ENV LC_ALL      C.UTF-8
RUN apt update \
    && apt upgrade -y \
    && apt install -y gcc git make curl
RUN git clone --recursive https://github.com/heiher/natmap.git \
    && cd natmap \
    && make \
    && cp ./bin/natmap /opt/natmap
ENTRYPOINT ["/opt/natmap"]

构建镜像

docker build -f ./dockerfiles/natmap/Dockerfile -t natmap .

docker-compose.yml

  natmap-wg:
    container_name: natmap-wg
    image: natmap
    command: -u -s stun.qq.com -b 30101 -t 127.0.0.1 -p 51820 -e /opt/cf_ip4p.sh -k 60
    volumes:
      - ./natmap/cf_ip4p.sh:/opt/cf_ip4p.sh
    cap_add:
      - NET_ADMIN
      - NET_RAW
    environment:
      - TZ=Asia/Shanghai
    network_mode: host
    restart: always

如果用python脚本的话,需要exec到容器内,再apt update && apt install python,其他的类似

@MikeWang000000
Copy link
Contributor

Thanks. 不过有一些建议可以作为参考:

  1. 可以采用多阶段 (Multi-stage builds) 的方式构建,这样可以避免把整个 GCC 打进镜像里面,减少镜像体积;
  2. NATMap 目前还没有内置 iptables 转发(虽然我曾提过这个事),NET_ADMIN NET_RAW 这两个权限还暂时用不到。

@MikeWang000000
Copy link
Contributor

@heiher 另外不知是否有构建 Docker 镜像的规划?如果有我可以帮忙提个 PR。

@Lxeon
Copy link
Author

Lxeon commented Mar 20, 2024

Thanks. 不过有一些建议可以作为参考:

1. 可以采用多阶段 (Multi-stage builds) 的方式构建,这样可以避免把整个 GCC 打进镜像里面,减少镜像体积;

2. NATMap 目前还没有内置 iptables 转发(虽然我曾提过这个事),`NET_ADMIN` `NET_RAW` 这两个权限还暂时用不到。

更新

FROM ubuntu:latest as builder
ENV LANG        C.UTF-8
ENV LANGUAGE    C.UTF-8
ENV LC_ALL      C.UTF-8
RUN apt update \
    && apt upgrade -y \
    && apt install -y gcc git make curl \
    && git clone --recursive https://github.com/heiher/natmap.git \
    && cd natmap \
    && make \
    && cp ./bin/natmap /opt/natmap
FROM ubuntu:latest
RUN apt update \
    && apt upgrade -y \
    && apt install -y curl
COPY --from=builder /opt/natmap /opt/natmap
ENTRYPOINT ["/opt/natmap"]

感觉有些常用的命令也得加上去

@heiher
Copy link
Owner

heiher commented Mar 20, 2024

@heiher 另外不知是否有构建 Docker 镜像的规划?如果有我可以帮忙提个 PR。

感谢 @Lxeon @MikeWang000000

如果能提个PR就太好了~ 有没有可能直接根据arch下载发布页由github action构建出来的二进制?那样会不会依赖简单一些

@doyoman
Copy link

doyoman commented Apr 8, 2024

不编译,直接下载最新Releases的对应架构文件到alpine镜像就行吧,做好启动脚本和对应环境变量就ok,这样体积应该非常小

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

No branches or pull requests

4 participants