Issue
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.
Solution
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
Answered By - quentic Answer Checked By - Terry (WPSolving Volunteer)