[英]How to map host port range (5000-5004) to the same port (80) in 5 different containers with docker-compose
[英]Docker Compose: Remap a containers port to be the same inside the network and on the host
我有兩個 dockerized 應用程序,它們是 docker 網絡的一部分,它們都在 8080 端口上啟動。 我需要將它們都暴露在主機上,這就是為什么我將它們相應地暴露給 8080 和 8081。
app-1:
ports:
- "8080:8080"
app-2:
ports:
- "8081:8080"
我無法控制這些應用程序(我無法更改它們的端口),它們只是端到端測試套件的一部分,需要運行才能執行測試。
Problem: Depending on wether I execute tests in a docker container (a 3d application in the same docker-compose file) or locally, I have to use different ports (8080 or 8081) because the requests go either within a docker network or over the host machine . 這很不方便。
問題:有沒有辦法重新映射 compose 文件中的端口,使 docker 網絡內外的端口相同? 例如,如果我可以使用docker網絡中的 8081 端口引用app-2
,那就太好了。
我會很感激任何提示。
我遇到了類似的問題,我使用以下方法解決了它。 這是一個 NodeJS-express 應用程序。
docker cp
將該文件復制到我的本地計算機上。使用docker cp
使用docker commit
該容器作為鏡像
在更新的端口上運行容器並使用新提交的映像。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.