Skip to content

using rustup in debian:latest docker image on macos x86_64 gives wrong version of rust (that won't run) #3544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
smoothdeveloper opened this issue Nov 26, 2023 · 8 comments
Labels
bug inactive incomplete The bug report does not have enough information

Comments

@smoothdeveloper
Copy link

Problem

installing rust via rustup on a debian:latest dockerimage on macos x86_64 seems to install 32 bit version of rust that doesn't run under the image.

$ rustc
error: command failed: 'rustc': No such file or directory (os error 2)

Steps

Dockerfile

FROM debian:latest

RUN apt-get update
RUN apt-get install -y gcc libc6-dev wget curl file
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

CMD bash

$ docker build . --progress=plain -t rustdev > builder.log 2>&1
$ docker run -it rustdev bash

Possible Solution(s)

No response

Notes

$ file ~/.cargo/bin/rustc

/root/.cargo/bin/rustc: ELF 32-bit LSB pie executable, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, with debug_info, not stripped

Rustup version

rustup 1.26.0 (5af9b9484 2023-04-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `(error reading rustc version)`

Installed toolchains

Default host: x86_64-unknown-linux-gnu
rustup home:  /root/.rustup

stable-x86_64-unknown-linux-gnu (default)
(error reading rustc version)
@smoothdeveloper
Copy link
Author

if I issue

$ rustup default stable-i686-unknown-linux-gnu

then it solves the issue, I'd prefer the image to not have workaround, the same image builds on aarch64 macos and pulls the aarch64 rustc which works out of the box.

@djc
Copy link
Contributor

djc commented Nov 28, 2023

Sorry you're having a bad experience!

I'm guessing there might be an issue in get_architecture(). Maybe you can look at that code/experiment with it to see how it could be improved for this case?

(Note that this links to the main branch which has evolved a bit from where the latest release was, so you might also just try compiling your own rustup from source to see if we have somehow already solved this.)

@rami3l
Copy link
Member

rami3l commented Nov 28, 2023

if I issue

$ rustup default stable-i686-unknown-linux-gnu

then it solves the issue, I'd prefer the image to not have workaround, the same image builds on aarch64 macos and pulls the aarch64 rustc which works out of the box.

... but the default host is indeed x86_64-unknown-linux-gnu which looks correct. Are you running a x86_32 container somehow (because you said that the i686 build did work)?

@smoothdeveloper
Copy link
Author

smoothdeveloper commented Dec 11, 2023

@djc, @rami3l thanks for the feedback and sorry for the delay.

I still can reproduce it, I ran the following to check what get_architecture() would resolve:

$ uname -s
Linux
$ uname -m
x86_64
$ uname -o
GNU/Linux

Are you running a x86_32 container somehow

Not sure how it could occur, as the image doesn't have a platform: moniker nor I specify one in the command line, but I'm just beginning with docker.

@rami3l
Copy link
Member

rami3l commented Dec 20, 2023

@smoothdeveloper You're running 64-bit Linux as your Docker host then.

However, ~/.cargo/bin/rustc is not rustc, but rustup.
If I have correctly understood your situation, you have downloaded a 32-bit rustup which cannot launch 64-bit rustc, as expected.
If you run rustc directly under ~/.rustup/toolchains however, it should work.

The problem here is why the script wants to install a 32-bit rustup for you. Would you mind checking again with https://raw.githubusercontent.com/rust-lang/rustup/master/rustup-init.sh instead of https://sh.rustup.rs and tell us what you have found?
Thanks a lot!

@rami3l rami3l self-assigned this Dec 20, 2023
@smoothdeveloper
Copy link
Author

@rami3l thanks for the guidance; I confirm that the binaries under ~/.rustup/toolchains/... are matching the expected architecture and can be run with no issue, your diagnosis seems consistent.

I built the same docker image with the rustup-init.sh url you mention, and it still seem to give the same outcome, here is the build log:

#0 building with "desktop-linux" instance using docker driver

#1 [internal] load .dockerignore
#1 transferring context: 2B done
#1 DONE 0.0s

#2 [internal] load build definition from Dockerfile
#2 transferring dockerfile: 433B done
#2 DONE 0.0s

#3 [internal] load metadata for docker.io/library/debian:latest
#3 DONE 0.0s

#4 [1/4] FROM docker.io/library/debian:latest
#4 DONE 0.0s

#5 [2/4] RUN apt-get update
#5 CACHED

#6 [3/4] RUN apt-get install -y gcc libc6-dev wget curl
#6 CACHED

#7 [4/4] RUN curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/rust-lang/rustup/master/rustup-init.sh | sh -s -- -y
#7 0.529 info: downloading installer
#7 2.459 info: profile set to 'default'
#7 2.459 info: default host triple is x86_64-unknown-linux-gnu
#7 2.459 info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
#7 2.728 info: latest update on 2023-12-07, rust version 1.74.1 (a28077b28 2023-12-04)
#7 2.728 info: downloading component 'cargo'
#7 3.513 info: downloading component 'clippy'
#7 3.765 info: downloading component 'rust-docs'
#7 5.097 info: downloading component 'rust-std'
#7 7.476 info: downloading component 'rustc'
#7 13.01 info: downloading component 'rustfmt'
#7 13.25 info: installing component 'cargo'
#7 14.27 info: installing component 'clippy'
#7 14.59 info: installing component 'rust-docs'
#7 18.06 info: installing component 'rust-std'
#7 21.06 info: installing component 'rustc'
#7 27.71 info: installing component 'rustfmt'
#7 28.10 
#7 28.10 info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'
#7 28.10   stable-x86_64-unknown-linux-gnu installed - (error reading rustc version)
#7 28.10 
#7 28.10 
#7 28.10 Rust is installed now. Great!
#7 28.10 
#7 28.10 To get started you may need to restart your current shell.
#7 28.10 This would reload your PATH environment variable to include
#7 28.10 Cargo's bin directory ($HOME/.cargo/bin).
#7 28.10 
#7 28.10 To configure your current shell, run:
#7 28.10 source "$HOME/.cargo/env"
#7 DONE 28.6s

#8 exporting to image
#8 exporting layers
#8 exporting layers 10.0s done
#8 writing image sha256:a7c999ae9a40d4f6123bef04b9d92f361729d03316dc29c055ed331dcef21eb9
#8 writing image sha256:a7c999ae9a40d4f6123bef04b9d92f361729d03316dc29c055ed331dcef21eb9 done
#8 naming to docker.io/library/rustdev done
#8 DONE 10.0s

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview

@rami3l
Copy link
Member

rami3l commented Dec 27, 2023

@smoothdeveloper We are making progress then, thank you!

Would you mind running the script again with the verbose mode on, e.g. with something like sh -x? If there is a problem in the downloader script, I would like to see more about the step downloading installer.

Also, since we are using /proc/self/exe to check for the default bitness, something like file $(which sh) might help as well.

@rami3l rami3l removed their assignment Jun 5, 2024
@rami3l rami3l added inactive incomplete The bug report does not have enough information labels Jun 5, 2024
@smoothdeveloper
Copy link
Author

Sorry for the delay, I still face the same, here is the full transcript with sh -x

root@ce8dd1e7dbb9:~/mecaviv $ apt-get install curl
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following NEW packages will be installed:
  curl
0 upgraded, 1 newly installed, 0 to remove and 13 not upgraded.
Need to get 319 kB of archives.
After this operation, 495 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian bookworm/main i386 curl i386 7.88.1-10+deb12u8 [319 kB]
Fetched 319 kB in 0s (2836 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package curl.
(Reading database ... 25315 files and directories currently installed.)
Preparing to unpack .../curl_7.88.1-10+deb12u8_i386.deb ...
Unpacking curl (7.88.1-10+deb12u8) ...
Setting up curl (7.88.1-10+deb12u8) ...
root@ce8dd1e7dbb9:~/mecaviv $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -x
+ has_local
+ set -u
+ RUSTUP_UPDATE_ROOT=https://static.rust-lang.org/rustup
+ main
+ downloader --check
+ is_zsh
+ [ -n  ]
+ local _dld
+ local _ciphersuites
+ local _err
+ local _status
+ local _retry
+ check_cmd curl
+ command -v curl
+ _dld=curl
+ [ --check = --check ]
+ need_cmd curl
+ check_cmd curl
+ command -v curl
+ need_cmd uname
+ check_cmd uname
+ command -v uname
+ need_cmd mktemp
+ check_cmd mktemp
+ command -v mktemp
+ need_cmd chmod
+ check_cmd chmod
+ command -v chmod
+ need_cmd mkdir
+ check_cmd mkdir
+ command -v mkdir
+ need_cmd rm
+ check_cmd rm
+ command -v rm
+ need_cmd rmdir
+ check_cmd rmdir
+ command -v rmdir
+ get_architecture
+ local _ostype _cputype _bitness _arch _clibtype
+ uname -s
+ _ostype=Linux
+ uname -m
+ _cputype=x86_64
+ _clibtype=gnu
+ [ Linux = Linux ]
+ uname -o
+ [ GNU/Linux = Android ]
+ ldd --version
+ grep -q musl
+ [ Linux = Darwin ]
+ [ Linux = SunOS ]
+ check_proc
+ test -L /proc/self/exe
+ _ostype=unknown-linux-gnu
+ get_bitness
+ need_cmd head
+ check_cmd head
+ command -v head
+ local _current_exe_head
+ head -c 5 /proc/self/exe
+ _current_exe_head=�ELF
+ printf \177ELF\001
+ [ �ELF = �ELF ]
+ echo 32
+ _bitness=32
+ _cputype=x86_64
+ [ unknown-linux-gnu = unknown-linux-gnu ]
+ [ 32 -eq 32 ]
+ [ -n  ]
+ is_host_amd64_elf
+ need_cmd head
+ check_cmd head
+ command -v head
+ need_cmd tail
+ check_cmd tail
+ command -v tail
+ local _current_exe_machine
+ head -c 19 /proc/self/exe
+ tail -c 1
+ _current_exe_machine=
+ printf \076
+ [  = > ]
+ _cputype=i686
+ [ unknown-linux-gnu = unknown-linux-gnueabihf ]
+ _arch=i686-unknown-linux-gnu
+ RETVAL=i686-unknown-linux-gnu
+ local _arch=i686-unknown-linux-gnu
+ assert_nz i686-unknown-linux-gnu arch
+ [ -z i686-unknown-linux-gnu ]
+ local _ext=
+ local _url=https://static.rust-lang.org/rustup/dist/i686-unknown-linux-gnu/rustup-init
+ local _dir
+ ensure mktemp -d
+ mktemp -d
+ _dir=/tmp/tmp.oCbM5XA88H
+ local _file=/tmp/tmp.oCbM5XA88H/rustup-init
+ local _ansi_escapes_are_valid=false
+ [ -t 2 ]
+ [ set = set ]
+ _ansi_escapes_are_valid=true
+ local need_tty=yes
+ true
+ printf \33[1minfo:\33[0m downloading installer\n
info: downloading installer
+ ensure mkdir -p /tmp/tmp.oCbM5XA88H
+ mkdir -p /tmp/tmp.oCbM5XA88H
+ ensure downloader https://static.rust-lang.org/rustup/dist/i686-unknown-linux-gnu/rustup-init /tmp/tmp.oCbM5XA88H/rustup-init i686-unknown-linux-gnu
+ downloader https://static.rust-lang.org/rustup/dist/i686-unknown-linux-gnu/rustup-init /tmp/tmp.oCbM5XA88H/rustup-init i686-unknown-linux-gnu
+ is_zsh
+ [ -n  ]
+ local _dld
+ local _ciphersuites
+ local _err
+ local _status
+ local _retry
+ check_cmd curl
+ command -v curl
+ _dld=curl
+ [ https://static.rust-lang.org/rustup/dist/i686-unknown-linux-gnu/rustup-init = --check ]
+ [ curl = curl ]
+ check_curl_for_retry_support
+ local _retry_supported=
+ check_help_for notspecified curl --retry
+ local _arch
+ local _cmd
+ local _arg
+ _arch=notspecified
+ shift
+ _cmd=curl
+ shift
+ local _category
+ curl --help
+ grep -q For all options use the manual or "--help all".
+ _category=all
+ + grep -q -- --retry
curl --help all
+ true
+ _retry_supported=--retry 3
+ check_help_for notspecified curl --continue-at
+ local _arch
+ local _cmd
+ local _arg
+ _arch=notspecified
+ shift
+ _cmd=curl
+ shift
+ local _category
+ curl --help
+ grep -q For all options use the manual or "--help all".
+ _category=all
+ curl --help all
+ grep -q -- --continue-at
+ true
+ _retry_supported=--retry 3 -C -
+ RETVAL=--retry 3 -C -
+ _retry=--retry 3 -C -
+ get_ciphersuites_for_curl
+ [ -n  ]
+ local _openssl_syntax=no
+ local _gnutls_syntax=no
+ local _backend_supported=yes
+ + grep -q  OpenSSL/curl
 -V
+ _openssl_syntax=yes
+ local _args_supported=no
+ [ yes = yes ]
+ check_help_for notspecified curl --tlsv1.2 --ciphers --proto
+ local _arch
+ local _cmd
+ local _arg
+ _arch=notspecified
+ shift
+ _cmd=curl
+ shift
+ local _category
+ curl --help
+ grep -q For all options use the manual or "--help all".
+ _category=all
+ curl --help all
+ grep -q -- --tlsv1.2
+ curl --help all
+ grep -q -- --ciphers
+ + grepcurl -q --help -- all --proto

+ true
+ _args_supported=yes
+ local _cs=
+ [ yes = yes ]
+ [ yes = yes ]
+ get_strong_ciphersuites_for openssl
+ [ openssl = openssl ]
+ echo TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
+ _cs=TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
+ RETVAL=TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
+ _ciphersuites=TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384
+ [ -n TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384 ]
+ curl --retry 3 -C - --proto =https --tlsv1.2 --ciphers TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384 --silent --show-error --fail --location https://static.rust-lang.org/rustup/dist/i686-unknown-linux-gnu/rustup-init --output /tmp/tmp.oCbM5XA88H/rustup-init
+ _err=
+ _status=0
+ [ -n  ]
+ return 0
+ ensure chmod u+x /tmp/tmp.oCbM5XA88H/rustup-init
+ chmod u+x /tmp/tmp.oCbM5XA88H/rustup-init
+ [ ! -x /tmp/tmp.oCbM5XA88H/rustup-init ]
+ [ yes = yes ]
+ [ ! -t 0 ]
+ [ ! -t 1 ]
+ ignore /tmp/tmp.oCbM5XA88H/rustup-init
+ /tmp/tmp.oCbM5XA88H/rustup-init

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /root/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory is located at:

  /root/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /root/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /root/.profile
  /root/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
>

info: profile set to 'default'
info: default host triple is x86_64-unknown-linux-gnu
info: syncing channel updates for 'stable-x86_64-unknown-linux-gnu'
info: latest update on 2025-01-09, rust version 1.84.0 (9fc6b4312 2025-01-07)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
 16.5 MiB /  16.5 MiB (100 %)  10.8 MiB/s in  1s ETA:  0s
info: downloading component 'rust-std'
 29.0 MiB /  29.0 MiB (100 %)  10.3 MiB/s in  2s ETA:  0s
info: downloading component 'rustc'
 70.6 MiB /  70.6 MiB (100 %)  10.3 MiB/s in  6s ETA:  0s
info: downloading component 'rustfmt'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
 16.5 MiB /  16.5 MiB (100 %)   7.3 MiB/s in  2s ETA:  0s
info: installing component 'rust-std'
 29.0 MiB /  29.0 MiB (100 %)  11.5 MiB/s in  2s ETA:  0s
info: installing component 'rustc'
 70.6 MiB /  70.6 MiB (100 %)  12.2 MiB/s in  6s ETA:  0s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-unknown-linux-gnu'

  stable-x86_64-unknown-linux-gnu installed - (error reading rustc version)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, you need to source
the corresponding env file under $HOME/.cargo.

This is usually done by running one of the following (note the leading DOT):
. "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
source "$HOME/.cargo/env.fish"  # For fish
+ local _retval=0
+ ignore rm /tmp/tmp.oCbM5XA88H/rustup-init
+ rm /tmp/tmp.oCbM5XA88H/rustup-init
+ ignore rmdir /tmp/tmp.oCbM5XA88H
+ rmdir /tmp/tmp.oCbM5XA88H
+ return 0
root@ce8dd1e7dbb9:~/mecaviv $ . "$HOME/.cargo/env"  
root@ce8dd1e7dbb9:~/mecaviv $ cargo
error: command failed: 'cargo': No such file or directory (os error 2)

and the output file $(which sh):

file $(which sh)
/usr/bin/sh: symbolic link to dash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug inactive incomplete The bug report does not have enough information
Projects
None yet
Development

No branches or pull requests

3 participants