I have a docker container built from the following image : FROM debian:9.11-slim
I try to install rust using the following line in my Dockerfile and it works fine until the last line. I get a permission denied error whenever I try to run /rust/cargo. However, if I connect to the container and run it from there via the command line it works. However, I need to be able to run rust/cargo commands from the docker file. Any help?
ENV RUSTUP_HOME=/rust/rustup
ENV CARGO_HOME=/rust/cargo
RUN set -eux;
url="https://raw.githubusercontent.com/rust-lang/rustup/1.22.1/rustup-init.sh";
wget -O rustup-init.sh "$url";
echo "b273275cf4d83cb6b991c1090baeca54 rustup-init.sh" | md5sum -c -;
echo "8928261388c8fae83bfd79b08d9030dfe21d17a8b59e9dcabda779213f6a3d14 rustup- init.sh" | sha256sum -c -;
bash ./rustup-init.sh --profile=minimal -y -t thumbv7em-none-eabihf;
rm rustup-init.sh;
chmod -R go+rwX /rust;
/rust/cargo --version
2
Answers
The problem is
chmod -R go+rwX
How to reproduce:
We have
file
:As you can see
-rw-rw-rw-
permissions don’t allow to execute fileSolution is to use something of below:
chmod -R ug+rwx /rust
(add all permissions to user and group)chmod -R ugo+rwx /rust
(add all permissions to all users)chmod -R 777 /rust
(add all permissions to all users (same as ugo+rwx))chmod -R 755 /rust
(add execution permissions to all users)chmod 755 /rust/cargo
(add execution permissions to all users only for execution file)chmod -R go+rwX /rust
) ← Best wayI faced a similar issue but in a slightly different situation. I was using docker-compose pipeline in GitHub actions on EC2 Self-Hosted Runner, based on the native GitHub pipeline. I didn’t remove the Rust toolchain installation, which caused reinstallation of cargo in every build on EC2 instance changing permissions and sourcing binaries from cargo
source ~/.cargo/env
, hence the permission error on the default system user.In my case, the solution was simply removing the installation of Rust from the workflow.yml and sourcing the system rust
source ~/.bashrc
.