docker-compose的端口号不变 [英] port number not change for docker-compose

查看:879
本文介绍了docker-compose的端口号不变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在docker-compose中指定了端口映射,但是仍然无法正常工作,我仍然必须使用暴露中未指定的端口访问站点

I have specified port-mapping in docker-compose, but it is still not working, i still have to access site using the port no specified in expose

以下是我的docker-compose.yml

version: '2'

networks:
  default:
    external:
      name: nat

services:

    website:
        build:
            context: '.'
            dockerfile: "./iis.dockerfile"
        ports:
            - 3000:8081

和相应的dockerfile

FROM microsoft/iis

RUN ["powershell.exe", "Install-WindowsFeature NET-Framework-45-ASPNET"]
RUN ["powershell.exe", "Install-WindowsFeature Web-Asp-Net45"]

ADD www/ c:\\webapp

EXPOSE 8081

RUN powershell New-Website -Name 'web-app' -Port 8081 -PhysicalPath 'c:\webapp' -ApplicationPool '.NET v4.5'

我必须使用http://192.168.105.33:8081/来访问应用程序,如果我使用端口3000则无法使用.

I have to access app using: http://192.168.105.33:8081/, if I do it using port 3000 it does not work.

上述配置中是否缺少任何内容?操作系统:windows server 2016,使用具有hyper-vdocker-compose up -d的Windows容器来启动并运行容器...

Is there anything missing in my above configuration?? OS: windows server 2016, using windows containers with hyper-v and docker-compose up -d to get containers up and running...

docker-compose inspect给我下面的输出

docker-compose inspect gives me below output

 "Ports": {
     "8081/tcp": [
         {
             "HostIp": "0.0.0.0",
             "HostPort": "3000"
         }
     ]
 },

docker ps给我下面的输出

  eb7aa1e74b7f        website_website     "C:\\ServiceMonitor..."   14 minutes ago      Up 14 minutes       0.0.0.0:3000->

8081/tcp website_website_1

8081/tcp website_website_1

dokcer-compose ps给我下面的输出

  Name                    Command             State           Ports
  --------------------------------------------------------------------------------
  website_website_1   C:\ServiceMonitor.exe w3svc   Up      0.0.0.0:3000->8081/tcp

所以我应该能够使用端口3000在主机上访问它.

So I should be able to access it on host using port 3000.

推荐答案

也许您正在使用docker-compose run启动容器? docker-compose rundocker-compose up [-d] [service]之间的端口映射有所不同,在这种情况下,端口配置为

Maybe you're launching your container with docker-compose run? There is a difference in port mapping between docker-compose run and docker-compose up [-d] [service] In this case the port configuration will be ignored by design You can use --service-ports flag or manually expose them using -p flag

这篇关于docker-compose的端口号不变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆