emk / rust-musl-builder

Docker images for compiling static Rust binaries using musl-libc and musl-gcc, with static versions of useful C libraries. Supports openssl and diesel crates.
Apache License 2.0
1.54k stars 193 forks source link

Permission denied on build #26

Closed stepankuzmin closed 6 years ago

stepankuzmin commented 6 years ago

Consider this Dockerfile:

# Our first FROM statement declares the build environment.
FROM ekidd/rust-musl-builder AS builder

# You would normally add your source code to /home/rust/src like this.
COPY . /home/rust/src/

# Build our application.
RUN cargo build --release

FROM alpine:latest
RUN apk --no-cache add ca-certificates
COPY --from=builder \
  /home/rust/src/target/x86_64-unknown-linux-musl/release/app \
  /usr/local/bin/
CMD /usr/local/bin/app

I'm getting following error on building image:

Sending build context to Docker daemon  27.14kB
Step 1/7 : FROM ekidd/rust-musl-builder AS builder
 ---> 92fa09f60317
Step 2/7 : COPY . /home/rust/src/
 ---> 2f52fde9c6f4
Step 3/7 : RUN cargo build --release
 ---> Running in 59cc9a3fd6f9
error: failed to open: /home/rust/src/target/release/.cargo-lock

Caused by:
  Permission denied (os error 13)
The command '/bin/sh -c cargo build --release' returned a non-zero code: 101

My app is simply generated with cargo new --bin app

emk commented 6 years ago

My apologies! I can think of two things you could try:

  1. Change the COPY . /home/rust/src/ to ADD . /home/rust/src. This may be a mistake in my example.
  2. Make sure the permissions on your source code are reasonable. It's possible there's a root versus rust issue here, and we may need to add a RUN sudo chmod -R /home/rust after the ADD.

Please let me know what works so I can fix the example!

stepankuzmin commented 6 years ago

Thanks for reply! I've tried both ADD . /home/rust/src and COPY . /home/rust/src/ and none of this worked. But it seems that setting permission directly helped. Thanks!

sononix commented 6 years ago

Any update on this - trying a cross build config - pulling the container from the repo 'ekidd/rust-musl-builder' and cant run the build command in the container rust@d0bb86cbdab6:~/src$ cargo build --release error: failed to open: /home/rust/src/target/release/.cargo-lock

Caused by: Permission denied (os error 13)

I running the latest builds rustc --version rustc 1.24.1 (d3ae9a9e0 2018-02-27)

cargo --version cargo 0.25.0 (96d8071da 2018-02-26)

sononix commented 6 years ago

Just ran the Dockerfile on the repo and getting an warning of debconf: delaying package configuration, since apt-utils is not installed

Also the creation of the container falls over with the following erorr Step 4/14 : ADD sudoers /etc/sudoers.d/nopasswd ADD failed: stat /var/lib/docker/tmp/docker-builder600994308/sudoers: no such file or directory

tbrand commented 6 years ago

I've faced the same error but fixed it by below

> cd ..
> sudo chown -R rust:rust src