skip to Main Content

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


  1. The problem is chmod -R go+rwX

    How to reproduce:

    We have file:

    #!/bin/bash
    
    echo good
    
    ~ $ ls -l file
    total 0
    -rw-r--r--  1 user  staff  0 Jun 30 11:49 file
    ~ $ ./file
    -bash: ./file: Permission denied
    ~ $ chmod go+rwX file
    ~ $ ls -l file
    -rw-rw-rw-  1 user  staff  23 Jun 30 11:50 file
    ~ $ ./file
    -bash: ./file: Permission denied
    

    As you can see -rw-rw-rw- permissions don’t allow to execute file

    Solution 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)
    • [if permissions already correct] don’t set permissions at all (remove chmod -R go+rwX /rust) ← Best way
    Login or Signup to reply.
  2. I 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search