Docker构成端口范围向前

问题描述 投票:2回答:1

这里的文档真的很缺乏。

ports:
  - "20000-20100"

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

- "20000-20100"
- "10000-10100:20000-20100"
- "20000-20100:20000-20100"

这些都不起作用

我在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->20003/tcp, 0.0.0.0:43805->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:43801->20008/tcp, 0.0.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"

Dockerfile

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"]
docker docker-compose dockerfile
1个回答
3
投票

我同意docker-compose ports documentation没有提供有关端口范围映射语法的足够信息。要了解语法,请检查docker run documentation on ports

特别是,

- "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

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

© www.soinside.com 2019 - 2024. All rights reserved.