Docker-compose 端口范围转发

Exc*_*dos 5 docker dockerfile docker-compose

这里确实缺乏文档。

ports:
  - "20000-20100"
Run Code Online (Sandbox Code Playgroud)

对一个端口工作正常(只是“20000”不起作用。它似乎绑定到某个 40k 以上的随机端口),但我找不到一种可靠的方法来转发一系列端口而不是一个端口。

- "20000-20100"
- "10000-10100:20000-20100"
- "20000-20100:20000-20100"
Run Code Online (Sandbox Code Playgroud)

这些作品都没有

我还在 Dockerfile 中公开了 20000-30000,但我的印象是这应该无关紧要。我在这里傻吗?这似乎是一件很容易的事情,但我已经敲打了几个小时,现在无法使连接正常工作。

编辑:

使用 - "20000-20010" 公开这些端口:

0.0.0.0:43809->20000/tcp, 0.0.0.0:43808->20001/tcp, 0.0.0.0:43807->20002/tcp, 0.0.0.0:43806->200503/tcp, 0.0.0.0:43808->20001/tcp >20004/tcp, 0.0.0.0:43804->20005/tcp, 0.0.0.0:43803->20006/tcp, 0.0.0.0:43802->20007/tcp, 0.0.0.0/->420cp, 0.0.0.0:43803->20006/tcp .0.0:43800->20009/tcp, 0.0.0.0:43799->20010/tcp

使用 - "20000-20010:20000-20010" 公开这些端口:

0.0.0.0:20000-20010->20000-20010/tcp

这似乎是正确的,但我实际上无法与它们建立任何联系。

Edit2: Docker-compose

version: '3.2'
services:
  sshd:
    build: .
    ports:
      - "23:22"
      - "20000-20010:20000-20010"
    environment:
      REDIS_ADDRESS: redis
      DEBUG: 'sshd:*,ioredis:*'
  web:
    image: controller_web
    ports:
      - target: 3000
        published: 3000
        protocol: tcp
        mode: host
    environment:
      REDIS_ADDRESS: redis
      DEBUG: 'sshd:*,ioredis:*'
  redis:
    image: "redis"
Run Code Online (Sandbox Code Playgroud)

文件

FROM node:alpine

# add openssh and clean
RUN apk add --update openssh \
&& rm  -rf /tmp/* /var/cache/apk/*

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

ARG NODE_ENV
ENV NODE_ENV $NODE_ENV
COPY package.json /usr/src/app/

RUN apk add --no-cache --virtual .gyp \
    python \
    make \
    g++

RUN npm install && npm cache clean --force
COPY . /usr/src/app

#make sure we get fresh keys
RUN rm -rf /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_dsa_key

EXPOSE 22
EXPOSE 20000-30000
ENTRYPOINT ["sh", "entrypoint.sh"]
CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)

yam*_*enk 7

我同意docker-compose 端口文档没有提供关于端口范围映射语法的足够信息。要了解语法,请查看有关 portsdocker run 文档

特别是,

- "20000-20100" means: Expose the container ports in the range 20000 to 20100 into random ports on the host machine
- "10000-10100:20000-20100" means: Expose the container ports in the range 20000 to 20100 into random ports on the host machine in the range of 10000 to 10100
- "20000-20100:20000-20100" similar to the above
Run Code Online (Sandbox Code Playgroud)

在您的情况下,所有这些都应该允许您访问容器化应用程序