我的 Ruby on Rails Web API 的 Docker 镜像无法构建容器。

huangapple go评论108阅读模式
英文:

My Docker image for a Ruby on Rails web API doesn't build a container

问题

我构建了一个Docker镜像来运行GA4咨询的Web API。在我的开发机上运行正常,但在生产环境(CentOS 7服务器)上,它无法构建镜像并返回以下错误:

[+] 正在构建 202.3s (8/10)                                       docker:default
 => [internal] load .dockerignore                                          0.0s
 => => 传输上下文: 2B                                                       0.0s
 => [internal] load build definition from dockerfile                       0.0s
 => => 传输dockerfile: 308B                                               0.0s
 => [internal] load metadata for docker.io/library/ruby:3.1.2              0.3s
 => [1/6] FROM docker.io/library/ruby:3.1.2@sha256:7681a3d37560dbe8ff7d0a  0.0s
 => [internal] load build context                                          0.0s
 => => 传输上下文: 3.65kB                                                    0.0s
 => CACHED [2/6] WORKDIR /app                                              0.0s
 => CACHED [3/6] COPY Gemfile Gemfile.lock ./                              0.0s
 => ERROR [4/6] RUN gem install bundler:2.2.28                           201.8s
------
 > [4/6] RUN gem install bundler:2.2.28:
121.3 ERROR:  无法找到有效的 gem 'bundler' (= 2.2.28),原因如下:
121.3           无法从 https://rubygems.org/ 下载数据 - SocketError: Failed to open TCP connection to rubygems.org:443 (getaddrinfo: Temporary failure in name resolution) (https://rubygems.org/specs.4.8.gz)
------
dockerfile:7
--------------------
   5 |     COPY Gemfile Gemfile.lock ./
   6 |
   7 | >>> RUN gem install bundler:2.2.28
   8 |     RUN bundle install
   9 |
--------------------
ERROR: failed to solve: process "/bin/sh -c gem install bundler:2.2.28" did not complete successfully: exit code: 2

我的 Dockerfile

FROM ruby:3.1.2

WORKDIR /app

COPY Gemfile Gemfile.lock ./

RUN gem install bundler
RUN bundle install

COPY . .

EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]

当运行以下命令时:

docker build -t api .

我会得到上述错误。

英文:

I built a Docker image to run a web API for GA4 consulting. It works fine on my development machine, but on production (centos 7 server), it fails to build the image and returns this error:

[+] Building 202.3s (8/10)                                       docker:default
 => [internal] load .dockerignore                                          0.0s
 => => transferring context: 2B                                            0.0s
 => [internal] load build definition from dockerfile                       0.0s
 => => transferring dockerfile: 308B                                       0.0s
 => [internal] load metadata for docker.io/library/ruby:3.1.2              0.3s
 => [1/6] FROM docker.io/library/ruby:3.1.2@sha256:7681a3d37560dbe8ff7d0a  0.0s
 => [internal] load build context                                          0.0s
 => => transferring context: 3.65kB                                        0.0s
 => CACHED [2/6] WORKDIR /app                                              0.0s
 => CACHED [3/6] COPY Gemfile Gemfile.lock ./                              0.0s
 => ERROR [4/6] RUN gem install bundler:2.2.28                           201.8s
------
 > [4/6] RUN gem install bundler:2.2.28:
121.3 ERROR:  Could not find a valid gem 'bundler' (= 2.2.28), here is why:
121.3           Unable to download data from https://rubygems.org/ - SocketError: Failed to open TCP connection to rubygems.org:443 (getaddrinfo: Temporary failure in name resolution) (https://rubygems.org/specs.4.8.gz)
------
dockerfile:7
--------------------
   5 |     COPY Gemfile Gemfile.lock ./
   6 |
   7 | >>> RUN gem install bundler:2.2.28
   8 |     RUN bundle install
   9 |
--------------------
ERROR: failed to solve: process "/bin/sh -c gem install bundler:2.2.28" did not complete successfully: exit code: 2

My Dockerfile:

FROM ruby:3.1.2

WORKDIR /app

COPY Gemfile Gemfile.lock ./

RUN gem install bundler
RUN bundle install

COPY . .

EXPOSE 3000

CMD ["rails", "server", "-b", "0.0.0.0"]`

when running the command:

docker build -t api .

I get the previous error.

答案1

得分: 1

似乎您的生产服务器上的Docker容器无法访问互联网,或者至少无法进行域名解析,因此出现了错误消息。
您的物理服务器能否访问互联网?如果可以,那么请检查为什么您的Docker容器与互联网隔离(查找Docker网络)。

祝好!

英文:

It seems that your docker container on your production server is not able to access the internet or at least a DNS for domain name résolution thus the error message.
Can your physical server access internet? If yes, then check why your docker container is isolated from the internet (look for docker networking)

Cheers

huangapple
  • 本文由 发表于 2023年7月14日 04:07:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682903.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定