Evy*_*005 6 ruby ubuntu docker
我是Docker新手,我正在尝试在 docker 中运行ruby 应用程序。所以我创建了一个可以正常工作和运行的 ruby 应用程序,我还创建了一个图像和一个 docker,当我运行和构建它们时,它运行得很好。运行 docker 后,它显示运行没有问题,我从中获得一个 IP docker inspect,端口显示为docker ps -a 3000。
当我在浏览器中打开 IP:端口时,我什么也看不到。
这是我的泊坞窗文件:
> 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"]
Run Code Online (Sandbox Code Playgroud)
编辑:
我还尝试了“ Expose 3000 ”,并使用“-p”标志运行。
当我运行“docker ps -a”时,端口为:“ 0.0.0.0:32768->3000/tcp ”。
对于“docker检查”我得到IP:“172.17.0.2”
但是当我在浏览器中访问“ http://172.17.0.2:3000/ ”时,我什么也没看到。
新编辑
我发现 docker 正在以 tcp6 (IPv6) 方式运行,我该如何将其配置为 tcp?。
在你的 dockerfile 中添加这一行:
EXPOSE 3000
Run Code Online (Sandbox Code Playgroud)
另外,如果您希望可以从主机访问此应用程序,请使用该-p标志运行。
有关文档,请参阅“通用表格” run。
我发现了我的问题。解决方案是将 docker 作为生产运行,而不是作为开发运行。
在Dockerfile中,而不是:
CMD ["bundle", "exec", "rails", "server"]
Run Code Online (Sandbox Code Playgroud)
我改为:
CMD ["bundle", "exec", "rails", "server", "-e", "production"]
Run Code Online (Sandbox Code Playgroud)
这解决了我的问题