所以我有以下Dockerfile:

FROM adoptopenjdk/openjdk13-openj9:alpine-jre

WORKDIR /opt/Lavalink

COPY Lavalink.jar Lavalink.jar
COPY application* ./

RUN if [[ -f "./application.local.yml" ]]; then mv "./application.local.yml" "./application.yml"; fi

EXPOSE 2333

CMD ["java", "-jar", "Lavalink.jar"]
然后由以下docker-compose.yml启动:
version: '2.4'
services:
  lavalink:
    network_mode: host
    container_name: lavalink
    image: skyrabot/lavalink:main
    restart: always
    ports:
      - '2333:2333'
但是,当我尝试连接到服务或检查docker ps时,我看到没有端口发布。
docker ps的输出:
> docker ps
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                            NAMES
e35e7cdea0a4        skyrabot/lavalink:main   "java -jar Lavalink.…"   7 minutes ago       Up 7 minutes                                                         lavalink
对我在这里可能做错的事情有任何想法吗?

最佳答案

问题出在network_mode: host行中。提供此选项时,Docker将使用主机网络而不是桥接它,并且它将完全忽略已配置的端口。您应该禁用/删除该行,或将其更改为network_mode: "bridge"。有关更多信息,请参见https://docs.docker.com/compose/compose-file/compose-file-v2/#network_mode

10-08 00:57