0

I am trying to build out a Docker container for a Substrate node chain, but I keep getting these errors that I am unable to rectify.

here is the Dockerfile

# Use the official Rust image as the base image
FROM rust:latest as builder

# Set the working directory inside the container
WORKDIR /usr/src/afloat

# Copy the Cargo.toml and Cargo.lock files to the container
COPY Cargo.toml Cargo.lock ./

# Copy the entire source code to the container
COPY . .

# Install necessary dependencies including libclang
RUN apt-get update && \
    apt-get install -y cmake clang libclang-dev && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Build the Polkadot node
RUN cargo build --release

# New stage to create a smaller image
FROM debian:buster-slim

# Set the working directory inside the container
WORKDIR /usr/local/bin/

# Copy the compiled binary from the builder stage
COPY --from=builder /usr/src/afloat/target/release/afloat .

# Expose the Polkadot ports
EXPOSE 30333 9933 9944

# Command to run the Polkadot node
CMD ["./afloat"]

Here is the error segment

463.6 error: failed to run custom build command for `sc-network-sync v0.33.0 (https://github.com/paritytech/polkadot-sdk.git?tag=polkadot-v1.9.0#3c3d6fce)`
463.6 
463.6 Caused by:
463.6   process didn't exit successfully: `/usr/src/afloat/target/release/build/sc-network-sync-73d336e1c2790a24/build-script-build` (exit status: 101)
463.6   --- stderr
463.6   thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/prost-build-0.11.9/src/lib.rs:1457:10:
463.6   Could not find `protoc` installation and this build crate cannot proceed without
463.6       this knowledge. If `protoc` is installed and this crate had trouble finding
463.6       it, you can set the `PROTOC` environment variable with the specific path to your
463.6       installed `protoc` binary.If you're on debian, try `apt-get install protobuf-compiler` or download it from https://github.com/protocolbuffers/protobuf/releases
463.6 
463.6   For more information: https://docs.rs/prost-build/#sourcing-protoc
463.6 
463.6   note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
463.6 warning: build failed, waiting for other jobs to finish...
------
Dockerfile:20
--------------------
  18 |     
  19 |     # Build the Polkadot node
  20 | >>> RUN cargo build --release
  21 |     
  22 |     # New stage to create a smaller image
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo build --release" did not complete successfully: exit code: 101

It seems to compile ok, but for some reason it errors out.

Many thanks in advance for your help

addendum

It was brought to my attention that it could not find protoc

So I added it to the Dockerfile

# Use the official Rust image as the base image
FROM rust:latest as builder

# Set the working directory inside the container
WORKDIR /usr/src/afloat

# Copy the Cargo.toml and Cargo.lock files to the container
COPY Cargo.toml Cargo.lock ./

# Copy the entire source code to the container
COPY . .

# Install necessary dependencies including protoc and libclang
RUN apt-get update && \
    apt-get install -y cmake clang libclang-dev protobuf-compiler && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Build the Polkadot node
RUN cargo build --release

# New stage to create a smaller image
FROM debian:buster-slim

# Set the working directory inside the container
WORKDIR /usr/local/bin/

# Copy the compiled binary from the builder stage
COPY --from=builder /usr/src/afloat/target/release/afloat .

# Expose the Polkadot ports
EXPOSE 30333 9933 9944

# Command to run the Polkadot node
CMD ["./afloat"]

But still getting errors about a checksum

 => [builder 6/6] RUN cargo build --release                                  993.1s 
 => ERROR [stage-1 3/3] COPY --from=builder /usr/src/afloat/target/release/af  0.0s 
------                                                                              
 > [stage-1 3/3] COPY --from=builder /usr/src/afloat/target/release/afloat .:       
------                                                                              
Dockerfile:29                                                                       
--------------------                                                                
  27 |     
  28 |     # Copy the compiled binary from the builder stage
  29 | >>> COPY --from=builder /usr/src/afloat/target/release/afloat .
  30 |     
  31 |     # Expose the Polkadot ports
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref a6793deb-f255-4bae-9bfd-180bc3588669::dc18i52b9g4u33ixd06t6630x: "/usr/src/afloat/target/release/afloat": not found

Ok I am trying to make progress, here is another Dockerfile build

# Use the official Rust image as the base image
FROM rust:latest as builder

# Set the working directory inside the container
WORKDIR /usr/src/afloat

# Copy the Cargo.toml and Cargo.lock files to the container
COPY Cargo.toml Cargo.lock ./

# Install necessary dependencies including protoc, libclang, and protobuf
RUN apt-get update && \
    apt-get install -y cmake clang libclang-dev protobuf-compiler && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

# Copy the entire source code to the container
COPY . .

# Build the project in release mode
RUN cargo build --release

# New stage to create a smaller image
FROM debian:buster-slim

# Set the working directory inside the container
WORKDIR /usr/local/bin/

# Copy the compiled binary from the builder stage
COPY --from=builder /usr/src/afloat/target/release/afloat .

# Expose the necessary ports
EXPOSE 30333 9933 9944

# Command to run the binary
CMD ["./afloat"]

I was told by my good friend Flipchan that I need to install the protobuf lib with apt and to clean the docker caches and images before rebuilding it.

But I am getting similar errors

 => ERROR [stage-1 3/3] COPY --from=builder /usr/src/afloat/target/releas  0.0s 
------                                                                          
 > [stage-1 3/3] COPY --from=builder /usr/src/afloat/target/release/afloat .:   
------                                                                          
Dockerfile:29                                                                   
--------------------
  27 |     
  28 |     # Copy the compiled binary from the builder stage
  29 | >>> COPY --from=builder /usr/src/afloat/target/release/afloat .
  30 |     
  31 |     # Expose the necessary ports
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref a6793deb-f255-4bae-9bfd-180bc3588669::npuqvl4pixuuultbckiqlasbt: "/usr/src/afloat/target/release/afloat": not found

Back to the drawing board....

1
  • What is the output of the build process? Can you replicate the step outside docker? Do you get an exe file in ./target/release/afloat
    – DerekC
    Commented May 17 at 13:41

1 Answer 1

0

To investigate your issue, comment out the COPY statement and just run the resulting container.

# Copy the compiled binary from the builder stage
# COPY --from=builder /usr/src/afloat/target/release/afloat .

# Expose the Polkadot ports
EXPOSE 30333 9933 9944

# Command to run the Polkadot node
#CMD ["./afloat"]
CMD ["/bin/bash"]

Build and run:

docker build -t afloat-debug .
docker run -it afloat-debug

Now you will be in a bash session. Try to execute the Dockerfile commands manually

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.