Skip to content

Create a Dockerfile that is able to build and run Substrate #2301

Open
@poppyseedDev

Description

Is there an existing issue?

  • I have searched the existing issues

Experiencing problems? Have you tried our Stack Exchange first?

  • This is not a support question.

Motivation

As a developer interested in using the polkadot-sdk for Substrate development and making it accessible for more people, I find that the process of setting up and configuring the environment to be somewhat complex, especially for newcomers. Having a Dockerfile that can build and run Substrate would streamline the development process, making it more accessible and efficient.

Request

I propose the creation of a Dockerfile within the polkadot-sdk repository, which would handle the following:

  1. Install all required dependencies for building Substrate.
  2. Build polkadot-sdk.
  3. Set up an environment to run the Substrate node.

This Dockerfile would abstract the complexity of environment setup and provide a straightforward path to getting Substrate running in a containerized environment.

Thank you for considering this request.

Solution

Something like this?

Dockerfile:

# Build stage for Substrate
FROM rust:latest as builder

# Install necessary build dependencies including cryptography package
RUN apt-get update && \
    apt-get install -y --no-install-recommends \
    build-essential \
    cmake \
    pkg-config \
    libssl-dev \
    clang \
    libclang-dev \
    protobuf-compiler \
    git \
    ca-certificates \
    llvm \
    libudev-dev \
    make \
    && rm -rf /var/lib/apt/lists/*

# Clone the GitHub repository
RUN git clone https://github.com/paritytech/polkadot-sdk.git

# Set the working directory to the cloned repository
WORKDIR /polkadot-sdk

# Install Rust toolchain and configure it
RUN rustup update && \
    rustup default stable && \
    rustup target add wasm32-unknown-unknown && \
    rustup update nightly && \
    rustup target add wasm32-unknown-unknown --toolchain nightly

# Build the project
RUN cargo build --release

# Use a smaller base image for the runtime environment
FROM debian:bookworm-slim as runtime

# Copy the built binary from the builder stage
COPY --from=builder /polkadot-sdk/target/release /usr/local/bin

# Expose necessary ports
EXPOSE 30333 9933 9944 9615

# Command to run the binary
CMD ["/usr/local/bin/substrate-node", "--dev", "--unsafe-rpc-external", "--rpc-cors", "all"]

Are you willing to help with this request?

Yes!

Metadata

Assignees

No one assigned

    Labels

    I10-unconfirmedIssue might be valid, but it's not yet known.I5-enhancementAn additional feature request.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions