Fork me on GitHub

Docker部署jar包

Dockerfile部署jar包

初始化docker

#生成默认文件
docker init

编辑dockerfile

#使用centos:7镜像(可以先手动拉下来)
FROM centos:7

# 替换为阿里云镜像源
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo && \
    yum clean all && \
    yum makecache

# 安装 openjdk 1.8 + wget + unzip
RUN yum install -y java-1.8.0-openjdk wget unzip && \
    yum clean all

#默认工作目录
WORKDIR /app

# 复制 jar 文件
COPY netty-stress-test-1.0-SNAPSHOT-jar-with-dependencies.jar /app/server.jar

# 设置代理
# ARG HTTP_PROXY
# ARG HTTPS_PROXY

# 启动 Netty 服务
CMD ["java", "-Dio.netty.tryReflectionSetAccessible=true", "-cp", "server.jar", "org.autumn.NettyServerTest"]

编译成镜像

docker build -t netty-server .

运行镜像为容器

docker run --rm -it --name netty-server -p 9000:9000 netty-server
posted @ 2025-06-06 14:56  秋夜雨巷  阅读(39)  评论(0)    收藏  举报