Published on 2020-04-09

Create a Docker Rust playground

Rust, Docker

As I start to learn Rust, in addition to the Rust playground, I want to create something more local. Docker seems like a good choice, but I don't want 1.8 GB image.

I found this Docker file (thanks Justin Cormack) which uses Alpine and what it creates is exactly what I need.

First, I create a file called Dockerfile with the following content:

FROM alpine:edge
RUN echo http:"//" >> /etc/apk/repositories && \
  apk update && apk upgrade && apk add \
  gcc musl-dev rust cargo

Once I have a Docker file, the next step is to build the image

$ docker build --tag alpinerust .

To verify the image has been built:

$ docker images

Now I can run it:

$ docker run --rm -it -e USER=%USERNAME% alpine /bin/sh

On Linux:

$ docker run --rm -it -e USER=$USER alpine /bin/sh

Now I get a prompt which indicates I'm inside a Linux Alpine machine. To verify that I can run Rust, type

# cargo

All is good. When done, simply type exit at the Linux prompt. To run again repeat

$ docker run --rm -it alpine /bin/sh
# cargo
# exit