port number not change for docker-compose

南楼画角 提交于 2020-01-04 01:55:10

问题


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

below is my docker-compose.yml

version: '2'

networks:
  default:
    external:
      name: nat

services:

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

and the corrosponding 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'

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

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 gives me below output

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

docker ps gives me below output

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

8081/tcp website_website_1

dokcer-compose ps gives me below output

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

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


回答1:


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



来源:https://stackoverflow.com/questions/41140554/port-number-not-change-for-docker-compose

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!