I try to build a docker image for the https://github.com/substrate-developer-hub/substrate-node-template.

I used this file to do it. Dockerfile.dev.

FROM paritytech/ci-linux:production as build

COPY . .
RUN cargo build --release

FROM ubuntu:22.04

# Copy the node binary.
COPY --from=build /code/target/release/node-template .

# Install root certs, see: https://github.com/paritytech/substrate/issues/9984
# RUN apt update && \
#     apt install -y ca-certificates && \
#     update-ca-certificates && \
#     apt remove ca-certificates -y && \
#     rm -rf /var/lib/apt/lists/*

CMD [ "./node-template", "--dev" ]

When I run docker build -f Dockerfile.dev -t wolfmorgan/xcavate-substrate-node ., I got this.

9.664 info: downloading component 'rust-analyzer'
11.02 info: downloading component 'rust-src'
11.43 info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
15.25 info: downloading component 'rust-std'
21.11 info: downloading component 'rustc'
35.06 info: downloading component 'rustc-dev'
54.36 info: downloading component 'rustfmt'
54.95 info: removing previous version of component 'rust-std' for 'wasm32-unknown-unknown'
59.43 info: rolling back changes
59.44 error: could not rename component file from '/usr/local/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-unknown-unknown/lib' to '/usr/local/rustup/tmp/pz7l5tq2toy2zfqw_dir/bk'
59.45 Caused by:
59.45     Invalid cross-device link (os error 18)
   3 |     WORKDIR /code
   4 |     COPY . .
   5 | >>> RUN cargo build --release
   6 |
   7 |     FROM ubuntu:22.04
ERROR: failed to solve: process "/bin/sh -c cargo build --release" did not complete successfully: exit code: 1

Please help me to fix this issue. Thank you in advance.

1 Answer 1


After some researching:

The issue arises from an incorrect built-in toolchain version. To resolve this, we should prioritize reading the project's rusttoolchain.toml file and updating the toolchain accordingly. However, this update may result in an "Invalid cross-device link (os error 18)" error. The solution is to remove the existing built-in toolchain and manually install it ourselves.


# This is an example build stage for the node template. Here we create the binary in a temporary image.

# This is a base image to build substrate nodes
FROM docker.io/paritytech/ci-linux:production as builder

WORKDIR /node-template
COPY . .
RUN rm -rf /usr/local/rustup /usr/local/cargo && \
    curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none && \
    rustup show && \
    cargo build --release

# This is the 2nd stage: a very small image where we copy the binary."
FROM docker.io/library/ubuntu:22.04
LABEL description="Multistage Docker image for Substrate Node Template" \
  image.type="builder" \
  image.authors="[email protected]" \
  image.vendor="Substrate Developer Hub" \
  image.description="Multistage Docker image for Substrate Node Template" \
  image.source="https://github.com/substrate-developer-hub/substrate-node-template" \

# Copy the node binary.
COPY --from=builder /node-template/target/release/node-template /usr/local/bin

RUN useradd -m -u 1000 -U -s /bin/sh -d /node-dev node-dev && \
  mkdir -p /chain-data /node-dev/.local/share && \
  chown -R node-dev:node-dev /chain-data && \
  ln -s /chain-data /node-dev/.local/share/node-template && \
  # unclutter and minimize the attack surface
  rm -rf /usr/bin /usr/sbin && \
  # check if executable works in this container
  /usr/local/bin/node-template --version

USER node-dev

EXPOSE 30333 9933 9944 9615
VOLUME ["/chain-data"]

ENTRYPOINT ["/usr/local/bin/node-template"]
  • Which image source should I use? @AurevoirXavier?
    – Alan Ma
    Aug 30 at 20:43
  • It is totally up to you. I use ubuntu:latest. Aug 30 at 23:27
  • I used ubuntu:latest, but got the same error.
    – Alan Ma
    Aug 31 at 6:40
  • What's your docker file content? Aug 31 at 6:54
  • It is not easy to paste here, if you let me know your email or other communication tool, i will contact via it.
    – Alan Ma
    Aug 31 at 7:14

Your Answer

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

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