Rust stable toolchain installed at build time not found at runtime

error: toolchain ‘stable-x86_64-unknown-linux-gnu’ is not installed despite already installed in the build command


build command:

#!/bin/bash 

rustup install stable &&
rustup default stable &&
rustup run stable cargo build --release --manifest-path ./rust/Cargo.toml ;

start command:

#!/bin/bash 

rustup run stable cargo run --release --manifest-path ./rust/Cargo.toml &
nginx -g 'daemon off;' &
echo "App is running" &
wait

environment variables:

CARGO_HOME=opt/render/project/.cargo
CARGO_LOG=cargo::core::compiler::fingerprint=info
RUSTUP_HOME=opt/render/project/.rustup
RUST_TOOLCHAIN=stable

Dockerfile:

# syntax=docker/dockerfile:1.2

FROM nginx

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain 1.73.0

COPY . /app
WORKDIR /app

ENV PATH="/root/.cargo/bin:$PATH"

RUN mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled
COPY nginx.conf /etc/nginx/conf.d/nginx.conf
COPY templates /etc/nginx/templates

RUN chmod +x /app/buildws.sh
RUN /app/buildws.sh
RUN chmod +x /app/startws.sh
ENV PORT=8080
EXPOSE 8080
CMD ["sh", "/app/startws.sh"]

Hi there,

Could you clarify if this is a Docker service or if you are running it as a Rust Native Environment?

Docker services do not have a build or start command, so if it’s a Docker-based service you’d just want to include any installations like this in your Dockerfile.

Let me know if you have any questions about this.

Regards,

Matt

it’s a docker service. I replaced

RUN chmod +x /app/buildws.sh
RUN /app/buildws.sh

with

RUN rustup install stable
RUN rustup default stable
RUN rustup run stable cargo build --release --manifest-path ./rust/Cargo.toml

but got the same error at runtime:
error: toolchain 'stable-x86_64-unknown-linux-gnu' is not installed

the following Dockerfile configuation solves the problem:

# syntax=docker/dockerfile:1.2

FROM nginx

COPY . /app
WORKDIR /app

RUN curl https://sh.rustup.rs -sSf | sh -s -- -y

# Add rust environment
ENV RUSTUP_HOME="/root/.rustup" \
    CARGO_HOME="/root/.cargo" \
    PATH="/root/.cargo/bin:${PATH}" \
    RUST_VERSION="1.75.0"
    
RUN cargo --version; \
    rustup --version; \
    rustc --version;

# nginx
RUN mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.disabled
COPY nginx.conf /etc/nginx/conf.d/nginx.conf
COPY templates /etc/nginx/templates

# Grant execute permissions to buildws.sh
RUN chmod +x /app/buildws.sh

# Install all dependencies
RUN sh /app/buildws.sh

# Grant execute permissions to startws.sh
RUN chmod +x /app/startws.sh

# Let Render detect service running on 8080
ENV PORT=8080
EXPOSE 8080

# Start websockets and nginx
CMD ["sh", "/app/startws.sh"]

the issue was most likely caused by incorrect environment variables
previously:

CARGO_HOME=opt/render/project/.cargo
(optional) CARGO_LOG=cargo::core::compiler::fingerprint=info
RUSTUP_HOME=opt/render/project/.rustup
RUST_TOOLCHAIN=stable
PATH=/root/.cargo/bin:$PATH

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.