Closed MrMic closed 4 months ago
I cannot reproduce the issue locally using the same image. I'm using this command to pull the exact same image as you used above and open in interactive Bash shell:
$ docker run -it rust@sha256:a71cd88f9dd32fbdfa67c935f55165ddd89b7166e95de6c053c9bf33dd7381d
In that shell, I'm then using curl
to fetch config.json
which works fine:
root@6aa30c25e68e:/# curl -I https://index.crates.io/config.json
HTTP/2 200
What happens when you run curl
in another container, e.g. ubuntu:latest
?
As a side note, your issue is very difficult to read. It would be much easier to parse if the shell output was inside a code block.
I cannot reproduce the issue locally using the same image. I'm using this command to pull the exact same image as you used above and open in interactive Bash shell:
$ docker run -it rust@sha256:a71cd88f9dd32fbdfa67c935f55165ddd89b7166e95de6c053c9bf33dd7381d
In that shell, I'm then using
curl
to fetchconfig.json
which works fine:root@6aa30c25e68e:/# curl -I https://index.crates.io/config.json HTTP/2 200
What happens when you run
curl
in another container, e.g.ubuntu:latest
?
Me too I can run:
$> docker run -it --rm --name test-rust rust:latest
But it is NOT what I do: I am trying to build a docker image with a Rust App inside. Try this: 1/ Create a project with:
$> cargo init test
2/ then, inside this project add a dependency, for example:
$> cargo add tokyo
3/ Create a Dockerfile, like this one:
FROM rust:latest
COPY . .
RUN cargo build --release
CMD [ "./target/release/test" ]
4/ And finally try to build the image with:
$> docker build .
As you can see in the following log, I can resolve docker.io to get the base image but the issue arise during the docker build ...
❯ docker build .
[+] Building 13.7s (7/7) FINISHED docker:default
=> [internal] load build definition from Dockerfile 0.1s
=> => transferring dockerfile: 184B 0.0s
=> [internal] load metadata for docker.io/library/rust:latest 0.9s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build context 0.1s
=> => transferring context: 69.38kB 0.0s
=> CACHED [1/3] FROM docker.io/library/rust:latest@sha256:a71cd88f9dd32fbdfa67c935f55165ddd89b7166e95de6c053c9bf33dd7381d5 0.0s
=> => resolve docker.io/library/rust:latest@sha256:a71cd88f9dd32fbdfa67c935f55165ddd89b7166e95de6c053c9bf33dd7381d5 0.0s
=> [2/3] COPY . . 0.1s
=> ERROR [3/3] RUN cargo build --release 12.4s
------
> [3/3] RUN cargo build --release:
1.073 Updating crates.io index
1.074 warning: spurious network error (3 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
2.225 warning: spurious network error (2 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
5.726 warning: spurious network error (1 tries remaining): [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
12.23 error: failed to get `tokyo` as a dependency of package `tets v0.1.0 (/)`
12.23
12.23 Caused by:
12.23 failed to query replaced source registry `crates-io`
12.23
12.23 Caused by:
12.23 download of config.json failed
12.23
12.23 Caused by:
12.23 failed to download from `https://index.crates.io/config.json`
12.23
12.23 Caused by:
12.23 [6] Couldn't resolve host name (Could not resolve host: index.crates.io)
------
Dockerfile:8
--------------------
6 | # ENV CARGO_HTTP_MULTIPLEXING=false
7 |
8 | >>> RUN cargo build --release
9 |
10 | CMD [ "./target/release/rust-web-dev" ]
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo build --release" did not complete successfully: exit code: 101
This drives me crazy!!! I cannot release anything for more than 1 week ...
Any help is welcome. Rgds,
Hm. I've went through the steps you listed, but cannot reproduce the issue locally. I also cloned https://github.com/MrMic/Rust_Web_Development and built the Dockerfiles in there without hitting the error. And judging from this build, the issue also doesn't appear on GitHub Actions. Given all of this, I still think this is a problem with your local Docker installation.
Can you try to reproduce the issue in a different container, e.g. ubuntu:latest
?
First, start the container:
docker run -it --rm --name docker-rust-176 ubuntu:latest
Inside the container, install curl
:
apt update
apt install curl
Then try to fetch the configuration:
curl -I https://index.crates.io/config.json
Everything is OK:
root@0317ba46a436:/# curl -I https://index.crates.io/config.json
HTTP/2 200
content-type: application/json
content-length: 76
last-modified: Mon, 23 May 2022 19:23:53 GMT
x-amz-version-id: OLJqOQ3bTJ8rGepGZwmcEkt2gR_Fm1bY
accept-ranges: bytes
server: AmazonS3
date: Fri, 23 Feb 2024 21:41:22 GMT
etag: "7a39851bdb021fcef53172317860f970"
vary: Accept-Encoding
x-cache: Hit from cloudfront
via: 1.1 ac3060b504d45421db0adf8239900fec.cloudfront.net (CloudFront)
x-amz-cf-pop: MRS52-P3
x-amz-cf-id: 7SiHLYm1wEHV-fVd1Uck3lXMKDR-YIjanV2nc2veC14ZYTkdnrGZvQ==
age: 451
What I cannot explain is that inside the Docker Image construction, I can
download the base image (so resolve the hostname where it comes from)
and failed to resolve crates.io to update the index , when cargo build
is invoked
inside the same Dockerfile.
I finally found the issue!
One has to add this key dns
to /etc/docker/daemon.json
on Ubuntu 20.04:
{
"insecure-registries" : ["localhost:32000"],
"dns": ["8.8.8.8"]
}
Thanks, @jdno for the hint about Docker installation. It helps me to search in another direction.
Rgds,
Great that you figured out the issue and that everything works now! 🥳
Hi,
When I try to build an image with Rust App, I got this:
=======================================================================
============================================================
Thank for the help. Rgds, Michaël