docker-library / openjdk

Docker Official Image packaging for EA builds of OpenJDK from Oracle
http://openjdk.java.net
MIT License
1.14k stars 475 forks source link

对于docker-compose构建镜像时中文乱码 #529

Closed fatebugs closed 9 months ago

fatebugs commented 1 year ago

你好,在我使用docker-compose.yml来进行部署Windows docker时会出现乱码的情况,类似于修改启动参数来指定字符集和使用CMD来重新设置chcp 65001来指定utf-8,这些依然不能解决问题,请问我应该怎么设置呢

附上我的dockerFile与docker-compose

#dockerFile

#基础镜像
FROM openjdk:11-jre

#作者
LABEL maintainer="fatebug"

#设置时区与编码
ENV chcp 65001
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

#暴露端口
EXPOSE 9290:9290

#创建目录
RUN mkdir -p C:\\Users\\xyh\\logs

#复制 jar 文件到目录
COPY ./jar/wsxyh-hx-templete-1.0-SNAPSHOT.jar C:\\Users\\xyh\\wsxyh-hx-templete.jar

#设置工作目录
WORKDIR C:/Users/xyh

#改字符集,设置内存大小,设置
ENTRYPOINT ["chcp", "65001"]
ENTRYPOINT ["java", "-jar", "wsxyh-hx-templete.jar", "-Dfile.encoding=UTF-8", "-Xms256m", "-Xmx256m", "-XX:PermSize=128m", "-XX:MaxPermSize=512M"]

#映射日志目录
VOLUME C:\\Users\\xyh\\logs
#docker-compose.yml

  wsxyh-hx-templete:
    container_name: wsxyh-hx-templete
    environment:
      - TZ=Asia/Shanghai
      - LANG=C.UTF-8
    build:
      context: ./xyh/wsxyh-hx-templete
      dockerfile: Dockerfile

    ports:
      - "9290:9290"
    volumes:
      - E:\projectXYH\logs:C:\Users\xyh\logs
tianon commented 1 year ago

There's a lot here (and a language barrier - unfortunately we're an all-English project and relying on in-browser Translate to even read this :bow:), so here are the top two biggest issues I see:

  1. openjdk:11-jre is long-since deprecated and not updated, so I'd highly recommend against using it (see the notice at the top of https://hub.docker.com/_/openjdk)

  2. your Dockerfile seems to be mixing Windows paths and Linux behavior/commands -- if you want Windows containers, you'll want to make sure you're explicitly using Windows commands and a Windows base image (on a Windows Docker daemon), but if you want Linux containers, you'll want to adjust all those paths in the image/Dockerfile to be Linux paths (and only use Windows paths on the left-hand-side of your bind mount in your docker-compose.yml)