简体   繁体   English

Dockerfile vs Docker运行

[英]Dockerfile vs docker run

I am having a problem with published ports in Docker using Dockerfile compared to using docker run manually. 与使用手动运行的docker相比,使用Dockerfile在Docker中发布的端口存在问题。 Using the following command, the Docker container starts successfully, and when I visit the Host IP address (192.168.99.100) in the browser with http://192.168.99.100:8080 – the RabbitMQ Web Management Dashboard loads. 使用以下命令,Docker容器成功启动,当我使用http://192.168.99.100:8080在浏览器中访问主机IP地址(192.168.99.100)时,RabbitMQ Web管理仪表板将加载。

docker run -d --hostname my-rabbit --name some-rabbit -p 8080:15672 rabbitmq:3.5.6-management

At this point, I run the following to free up the ports I want to use from the Dockerfile: 此时,我运行以下命令从Dockerfile中释放要使用的端口:

docker stop some-rabbit

When I run the following docker-compose commands, once I visit the same URL above ( http://192.168.99.100:8080 ) I receive "This site can't be reached 192.168.99.100 refused to connect." 当我运行以下docker-compose命令时,一旦访问上述相同的URL( http://192.168.99.100:8080 ),我将收到“无法访问该站点,192.168.99.100拒绝连接。”

docker-compose build
docker-compose up -d

Here is the Dockerfile I am using: 这是我正在使用的Dockerfile:

version: '2'
services:
    rabbitmq:
        container_name: rabbit
        hostname: rabbit
        ports:
            - "8080:15762"
        image: rabbitmq:3.5.6-management

Below is the result of docker ps after docker run 以下是docker rundocker run docker ps的结果

6c5a97bd51bc rabbitmq:3.5.6-management "/docker-entrypoint.s" 16 seconds ago Up 15 seconds 4369/tcp, 5671-5672/tcp, 15671/tcp, 25672/tcp, 0.0.0.0:8080->15672/tcp some-rabbit

Below is the result of docker ps after docker-compose up -d 以下是docker-compose up -d之后docker-compose up -d docker ps的结果

99987aeb5cbf rabbitmq:3.5.6-management "/docker-entrypoint.s" 13 seconds ago Up 11 seconds 4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp, 0.0.0.0:8080->15762/tcp rabbitmq

After further testing, I discovered that all ports used by RabbitMQ must be explicitly published in the Dockerfile. 经过进一步测试后,我发现RabbitMQ使用的所有端口必须在Dockerfile中显式发布。

version: '2'
services:
    rabbitmq:
        container_name: rabbitmq
        hostname: rabbitmq
        ports:
            - "4369:4369"
            - "5672:5672"
            - "15672:15672"
            - "25672:25672"
        image: rabbitmq:3.5.5-management

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM