A simple build (and run) machine with latest dmd and ldc2 compilers, based on ubuntu.
240
The dlang-ubuntu Docker image is designed to streamline the development process for D language enthusiasts. It automatically downloads and installs the latest versions of the D compilers: dmd (Digital Mars D) and ldc2 (LLVM D Compiler), ensuring that you have the most up-to-date tools at your disposal.
Based on Ubuntu, this Docker image provides a stable and familiar environment for building and running your D applications.
This command start the docker binding the current directory (your project directory) to /home/ubuntu/src directory (of docker container).
docker run -h dlang-ubuntu -v $(pwd):/home/user/src -ti --rm trikko/dlang-ubuntu
You can use this docker to build the project in the current directory, using dub. To avoid downloading all the necessary dub packages at every build, it is useful to add a binding of the /home/user/.dub folder located inside the docker with a local folder on your machine, in this way:
docker run -h dlang-ubuntu -v $(pwd):/home/user/src -v ~/.docker-dub:/home/user/.dub -ti --rm trikko/dlang-ubuntu dub
Maybe you want to put this inside a bash script like:
#!/bin/bash
uid=`echo -n $(pwd) | md5sum | head -c32`
bname=`basename $(pwd)`
dub_pkg_dir="$HOME/.dlang-docker-dub"
# if you want to have a different build dir for each project:
# dub_pkg_dir="$(pwd)/.dlang-docker-dub"
docker_cmd="docker run --name dlang-docker-$uid-$bname -h dlang-ubuntu -v \$(pwd):/home/user/src -ti --rm"
for param in "$@"
do
if [ "$param" == "dub" ]; then
docker_cmd+=" -v $dub_pkg_dir:/home/user/.dub trikko/dlang-ubuntu dub"
continue
elif [ "$param" == "dmd" ]; then
docker_cmd+=" trikko/dlang-ubuntu dmd"
continue
elif [ "$param" == "ldc2" ]; then
docker_cmd+=" trikko/dlang-ubuntu ldc2"
continue
fi
docker_cmd+=" $param"
done
echo "----------------------------------"
echo "--- 🤖 Running on docker! 🤖 ---"
echo "----------------------------------"
echo
echo "container: dlang-docker-$uid-$bname"
echo
mkdir -p $dub_pkg_dir
docker container rm -f dlang-docker-$uid-$bname &>/dev/null
eval $docker_cmd
Assuming you have named the file run.sh and have given it execution permissions (eg: chmod +x run.sh), you can use the script like this:
# Run dub inside docker
./run.sh dub --build=release
# You can run also dmd and ldc2
./run.sh dmd --version
# Port mapping param is passed to docker
./run.sh -p 8081:8080 dub
Sometime you need to add some extra libraries or config inside the docker. Write a simple dockerfile like this:
FROM trikko/dlang-ubuntu
# Update packages
RUN sudo apt-get update
# Do you need libsqlite3?
RUN sudo apt-get -fy install libsqlite3-dev
Then build your machine:
docker build -t your_custom_docker -f /path/to/Dockerfile .
Try your new docker with libsqlite3 installed:
docker run -h dlang-ubuntu -v $(pwd):/home/user/src --rm -ti your_custom_docker
Content type
Image
Digest
sha256:1c1811739…
Size
539.7 MB
Last updated
over 2 years ago
docker pull trikko/dlang-ubuntu