gpt4 book ai didi

ruby - Docker容器正在运行但无法在浏览器中查看

转载 作者:数据小太阳 更新时间:2023-10-29 08:43:14 24 4
gpt4 key购买 nike

我是 Docker 的新手,我正在尝试在 docker 中运行 ruby 应用程序。所以我创建了一个运行良好的 ruby​​ 应用程序,我还创建了一个图像和一个 docker,当我运行和构建它们时它运行得很好。在我运行 docker 之后,它显示它运行没有问题,我从 docker inspect 获得了一个 IP,并且在 docker ps -a 中显示的端口为 3000。

当我在浏览器中打开 IP:port 时,我什么也看不到。

这是我的 docker 文件:

> FROM ruby:latest 
>
> # Set the working directory to /app WORKDIR /app
>
> # Copy the current directory contents into the container at /app ADD . /app
>
> RUN echo 'debconf debconf/frontend select Noninteractive' |
> debconf-set-selections RUN apt-get update \
> && DEBIAN_FRONTEND=Noninteractive apt-get install -y \
> sqlite3 \
> thin \
> nodejs \
> apt-utils \
> && bundle install
> # --no-install-recommends apt-utils sudo
>
>
> #RUN sudo -H cp config/initializers/rack_attack.rb config/initializers/rack_attack.rb
>
> # Install any needed packages specified in requirements.txt
> # RUN pip install -r requirements.txt
> EXPOSE 3000
>
> CMD ["bundle", "exec", "rails", "server"]

编辑:

我也尝试过使用“Expose 3000”并使用“-p”标志运行。
当我运行“docker ps -a”时,端口是:“0.0.0.0:32768->3000/tcp”。
对于“docker inspect”,我得到了 IP: '172.17.0.2'

但是当我去'http://172.17.0.2:3000/ ' 在浏览器中我什么也看不到。

新编辑

I discover that the docker is running as tcp6 (IPv6), how can i configure it to be tcp? .

最佳答案

在您的 dockerfile 中添加此行:

EXPOSE 3000

此外,如果您希望可以从您的主机访问此应用程序,请使用 -p 标志运行。

请参阅“General form”以获取run 文档。

关于ruby - Docker容器正在运行但无法在浏览器中查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43897673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com