From 2a6835f4b7aeba759beef53cf2d6f7e7da841a5d Mon Sep 17 00:00:00 2001 From: Ewen McNeill Date: Sat, 7 Jan 2023 14:58:20 +1300 Subject: [PATCH] ch6: particles: usable Dockerfile Update Dockerfile: (a) to Rust 1.66 (current stable release) (b) to fix Cargo.lock cleanup ([[ ]] is bash built in only, not available) (c) install necessary X11 dependencies to actually run (d) fix the CMD to refer to the actual built filename (and path) And also provide examples of how to build and run it, so that, at least from an Ubuntu 20.04 LTS host, it is actually possible to see the graphical output. --- ch6/ch6-particles/Dockerfile | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ch6/ch6-particles/Dockerfile b/ch6/ch6-particles/Dockerfile index ea4ce2fe..5acec8d9 100644 --- a/ch6/ch6-particles/Dockerfile +++ b/ch6/ch6-particles/Dockerfile @@ -1,7 +1,22 @@ -FROM rust:1.30 +# Build container with: +# +# docker build . --tag particles +# +# Run container with something like: +# +# XSOCK=/tmp/.X11-unix +# XAUTH=/tmp/.docker.xauth +# touch "${XAUTH}" +# xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f "${XAUTH}" nmerge - +# docker run -ti -v /etc/passwd:/etc/passwd:ro -v /etc/group:/etc/group:ro -v "${XSOCK}:${XSOCK}" -v "${XAUTH}:${XAUTH}" -v /dev/dri/card0:/dev/dri/card0 -e "XAUTHORITY=${XAUTH}" -e DISPLAY -e HOME -e USER --user "$(id -u):$(id -g)" --rm particles +# +FROM rust:1.66 + +RUN apt-get update +RUN apt-get -y install libxcursor-dev libxrandr2 libxi6 libx11-xcb1 libgl1 WORKDIR /opt/particles COPY . . -RUN [[ -f Cargo.lock ]] && rm Cargo.lock || true +RUN test -f Cargo.lock && rm Cargo.lock || true RUN cargo build -CMD ["particles"] +CMD ["/opt/particles/target/debug/ch6-particles"]