Replying to Avatar kohanucha

#siamstr

วันนี้มาแจกตัวอย่าง Dockerfile สำหรับ build electrs server docker image เผื่อใครสนใจทำไว้ run เล่นเองที่บ้านครับ

Dockerfile

```

FROM rust:slim-bookworm AS build

# Declare build args

ARG VERSION=master

# Install build dependencies

RUN apt-get update && apt-get install -qqy \

clang cmake build-essential git pkg-config libssl-dev \

librocksdb-dev

# Clone and build electrs

RUN git clone https://github.com/romanz/electrs.git /electrs && \

cd /electrs && \

git checkout ${VERSION} && \

cargo build --locked --release

FROM debian:bookworm-slim AS runtime

# Declare runtime args

ARG UID=

ARG GID=

ARG USERNAME=

ARG GROUPNAME=

# Create group and user

RUN groupadd -g ${GID} ${GROUPNAME} && \

useradd -u ${UID} -g ${GID} -m -s /bin/bash ${USERNAME} && \

mkdir -p /home/${USERNAME}/electrs/bin /home/${USERNAME}/electrs/db /home/${USERNAME}/electrs/bitcoin && \

chown -R ${USERNAME}:${GROUPNAME} /home/${USERNAME}

# Copy the built binary

COPY --from=build /electrs/target/release/electrs /home/${USERNAME}/electrs/bin/

# Switch to non-root user

USER ${USERNAME}

WORKDIR /home/${USERNAME}/electrs

# Expose port 50001

EXPOSE 50001

# Run the binary

CMD ["./bin/electrs"]

```

build.sh

```

#!/bin/bash

VERSION=v0.10.9

export VERSION=${VERSION}

docker buildx build --build-arg VERSION -t electrs:${VERSION} /path/to/dockerfile

```

ของดีเลย

Reply to this note

Please Login to reply.

Discussion

ขอบคุณครับ