Docker image with dfx and icp dependencies

I’m working on some abstractions to make it easier for a developer to start working on ICP smart contracts and as part of that I created this docker image.

I wanted to share if anyone has been looking for it:

https://hub.docker.com/r/cryptoisgood/wdfx

Share any issues you find please

5 Likes

Hey, would be great if you could also provide a link to the repo with the Dockerfile.

Thanks!

1 Like

I tried to implement a Dockerfile using this as a reference (I didn’t could use this one because it has old dependencies), but when I run “dfx deploy” I have next error:

2023-11-05T06:05:59.750744Z ERROR icx_proxy_dev::proxy: Internal Error during request:
error trying to connect: tcp connect error: Cannot assign requested address (os error 99)
2023-11-05T06:05:59.755699Z ERROR tower_http::trace::on_failure: response failed classification=Status code: 500 Internal Server Error latency=21 ms

Mi Dockerfile is:

FROM --platform=linux/amd64 ubuntu:22.04

# replace shell with bash so we can source files
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

# Prepare workdir
WORKDIR /root/dfx

# Update the apt package list and install the required packages
RUN apt -yq update && \
    apt -yqq install --no-install-recommends curl ca-certificates \
    build-essential pkg-config libssl-dev llvm-dev liblmdb-dev clang cmake rsync \
    libunwind8

# Clean apt
RUN apt autoremove && apt clean

# Install Node
ENV NVM_VERSION=v0.39.5
RUN curl --fail -sSf https://raw.githubusercontent.com/creationix/nvm/${NVM_VERSION}/install.sh | bash
ENV NVM_DIR=/root/.nvm
ENV NODE_VERSION=18
RUN . "${NVM_DIR}/nvm.sh" && nvm install ${NODE_VERSION}
RUN . "${NVM_DIR}/nvm.sh" && nvm use v${NODE_VERSION}
RUN . "${NVM_DIR}/nvm.sh" && nvm alias default v${NODE_VERSION}
ENV PATH="/root/.nvm/versions/node/default/bin/:${PATH}"

# Install Rust and Cargo
ENV RUSTUP_HOME=/opt/rustup \
    CARGO_HOME=/cargo \
    PATH=/cargo/bin:$PATH

COPY ./scripts ./scripts
COPY ./rust-toolchain.toml ./rust-toolchain.toml

RUN sh ./scripts/rust-bootstrap

# Install IC SDK
ENV DFX_VERSION=0.15.1
RUN sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"

SHELL ["/bin/bash", "-c"]
CMD tail -f /dev/null

rust-toolchain.toml

[toolchain]
channel = "1.73.0"
targets = ["wasm32-unknown-unknown"]

rust-bootstrap

#!/usr/bin/env bash
# install build dependencies (rustup + ic-wasm)

set -euo pipefail

SCRIPTS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
cd "$SCRIPTS_DIR/.."

function run() {
    1>&2 echo "running $@"
    rc=0 && "$@" || rc="$?"
    if ! [ "$rc" -eq 0 ]
    then
        1>&2 echo "Bootstrap command failed: $@"
        exit "$rc"
    fi
}

rust_version=$(cat ./rust-toolchain.toml | sed -n 's/^channel[[:space:]]*=[[:space:]]"\(.*\)"/\1/p')
echo "using rust version '$rust_version'"

# here we set the toolchain to 'none' and rustup will pick up on ./rust-toolchain.toml
run curl --fail https://sh.rustup.rs -sSf | run sh -s -- -y --default-toolchain "none" --no-modify-path

echo "looking for ic-wasm 0.3.5"
if [[ ! "$(command -v ic-wasm)" || "$(ic-wasm --version)" != "ic-wasm 0.3.5" ]]
then
    echo "installing ic-wasm 0.3.5"
    run cargo install ic-wasm --version 0.3.5
fi

The command for build it is:

docker buildx build --platform=linux/amd64 -t {{image-name}} . --output type=docker

Run command:

docker run --platform linux/amd64 --name {{container-name}} -it {{image-name}} bash

I tried to create a development environment with a docker container for VSCODE, but it failed with an error.

Dev Containers 0.388.0 in VS Code 1.91.1 (f1e16e1e6214d7c44d078b1f0607b2388f29d729).

Something seems to be out of date.

=> ERROR [builder 5/13] RUN cargo install --version 0.3.4 ic-cdk-optim 94.0s

93.41 error: failed to compile ic-cdk-optimizer v0.3.4, intermediate artifacts can be found at /tmp/cargo-install7HiCHn
93.41
93.41 Caused by:
93.41 package regex-syntax v0.8.5 cannot be built because it requires rustc 1.65 or newer, while the currently active rustc version is 1.62.0

Dockerfile-with-features:32

30 | rustup default ${RUST_VERSION}-x86_64-unknown-linux-gnu &&
31 | rustup target add wasm32-unknown-unknown
32 | >>> RUN cargo install --version ${IC_CDK_OPTIMIZER_VERSION} ic-cdk-optimizer
33 |

34
ERROR: failed to solve: process “/bin/sh -c cargo install --version ${IC_CDK_OPTIMIZER_VERSION} ic-cdk-optimizer” did not complete successfully: exit code: 101
[110717 ms] Error: Command failed: docker buildx build --load --build-arg BUILDKIT_INLINE_CACHE=1 -f /tmp/devcontainercli-root/container-features/0.71.0-1728170645288/Dockerfile-with-features -t vsc-ic-3-fe714d99f2d7c8f3e394b33fa8bbd5aec112356bd6a2e037ed4ffa1a51bce424 --target dev_containers_target_stage --build-arg _DEV_CONTAINERS_BASE_IMAGE=builder /workspaces/ic-3/.devcontainer

[110744 ms] Exit code 1
[110745 ms] Start: Run: docker rm -f 6ed87b589eb7f94bb02ac7df73275b8b75bc1cee65d5ef5da478ac5f660b2562
[110758 ms] Command failed: node /root/.vscode-remote-containers/dist/dev-containers-cli-0.388.0/dist/spec-node/devContainersSpecCLI.js up --container-session-data-folder /tmp/devcontainers-46e14e83-27dc-4f99-ba60-10c61b19bb9d1728170628112 --workspace-folder /workspaces/ic-3 --workspace-mount-consistency cached --gpu-availability detect --id-label vsc.devcontainer.volume.name=ic-3 --id-label vsc.devcontainer.volume.folder=ic-3 --id-label devcontainer.config_file=/workspaces/ic-3/.devcontainer/devcontainer.json --log-level debug --log-format json --config /workspaces/ic-3/.devcontainer/devcontainer.json --override-config /tmp/devcontainer-d26f0caf-8ae9-4c19-942b-427e00293463.json --default-user-env-probe loginInteractiveShell --mount type=volume,source=ic-3,target=/workspaces,external=true --mount type=volume,source=vscode,target=/vscode,external=true --skip-post-create --update-remote-user-uid-default off --mount-workspace-git-root --include-configuration --include-merged-configuration
[110758 ms] Exit code 1

Looks like one of the dependencies decided to bump the minimum Rust version in a patch version. You can either upgrade your own Rust version or use a lockfile together with --locked to use a version that doesn’t bump the Rust version