我构建了一个Docker映像来运行用于GA4咨询的Web API.它在我的开发机器上运行得很好,但在生产环境(Centos 7服务器)上,它无法构建映像并返回以下错误:
[+] 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
我的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 .
我得到了前面的错误.