dockerfile CMD – 在不同端口上启动服务器

我在docker中有两个rails应用程序,我想在同一时间使用docker-compose up ,但是我想在不同的端口上启动每个应用程序。

我有一个不同的dockerfile为每个应用程序,与一个共享的docker-compose.yml。 docker-compose为每个应用程序有2个条目。

这里是一个Dockerfile的例子,但由于某种原因,它不可访问或不在指定的端口上启动:

  Expose port to the Docker host, so we can access it # from the outside. EXPOSE 5000 # Configure an entry point, so we don't need to specify # "bundle exec" for each of our commands. ENTRYPOINT ["bundle", "exec"] # The main command to run when the container starts. Also # tell the Rails dev server to bind to all interfaces by # default. CMD ["bundle", "exec", "rails", "server”,”-p”, “5000”, "-b", "0.0.0.0"] 

CMD的语法有问题吗?

docker-compose有下面的代码片断,这表明我允许主机的端口5000访问端口5000在容器中,但似乎服务器没有在端口5000上运行:

 ports: - "5000:5000" 

有什么遗漏?

  1. 这是从主机curl问题吗? 或者一个容器无法与另一个容器交谈的问题
  2. 你使用主机networking?
  3. 如果您在docker-compose.yml中指定了端口映射,则不需要使用EXPOSE
  4. 您确定您的服务器正在指定的主机/端口上运行吗?

我看不出你的CMD什么问题,但是同时使用CMDENTRYPOINT是非常不寻常的。 我可以看到你为什么在这里做,但我会尝试拿出进入ENTRYPOINT 。 最后,说服服务器确实在主机/端口上运行是有帮助的。 你可以试试

 docker run -it "my/image" bash > rails s -p 5000 -b 0.0.0.0 -d > curl 0.0.0.0:5000 # should show your landing page if the server is indeed running on port 5000.