#!/bin/bash # See https://nextbreakpoint.com/posts/article-compile-code-with-docker.html # sudo docker build -t lmk-devuan-chimaera-img dyne/devuan:chimaera echo "* This container is only for the server, not the client." sleep 10 docker_path="`sudo bash -c 'command -v docker'`" ENABLE_RUN_CLIENT=false for var in "$@" do if [ "@$var" = "@--run-client" ]; then ENABLE_RUN_CLIENT=true fi done if [ ! -f "$docker_path" ]; then cat < or Docker's own documentation at . END fi container_name="lmk-devuan-chimaera" image_name="lmk-devuan-chimaera-img" # client_classic_image=linux-minetest-kit/client-classic server_finetest_image=linux-minetest-kit/server-finetest # client_classic_container="minetest-client-classic" server_container="minetestserver-finetest" docker_image_dir="lmk.devuan-chimaera" if [ ! -d "$docker_image_dir" ]; then echo "* $me must run from the directory containing the container image directory: $docker_image_dir" exit 1 fi container_build_blob=$docker_image_dir/linux-minetest-kit.zip # ^ docker_image_dir has to be in the same directory as Dockerfile or # the COPY command in the Dockerfile won't work. source $docker_image_dir/lmk.rc if [ $? -ne 0 ]; then exit 1 fi me=lmk.devuan-chimaera.sh if [ "@$DL_SRC_PATH" = "@" ]; then # DL_SRC_PATH="$HOME/Downloads/$DL_SRC_NAME" DL_SRC_PATH="$docker_image_dir" # ^ $DL_SRC_PATH has to be in the same directory as Dockerfile or # the COPY command in the Dockerfile won't work. # The file should be added to .gitignore for the reason that it # is in the repo in the docker image directory. fi # sudo docker image inspect $image_name > /dev/null sudo docker image inspect $image_name --format "* docker is looking for the image..." # ^ appending ":latest" to the name also works. # ^ Get matching images as a JSON list (where each has "Id" and other # metadata). if [ $? -ne 0 ]; then if [ ! -d "$docker_image_dir" ]; then echo "Error: \"$docker_image_dir\" (docker_image_dir for storing $SRC_URL) doesn't exist in \"`pwd`\"." exit 1 fi if [ ! -f "$container_build_blob" ]; then echo "* downloading $SRC_URL to $DL_SRC_PATH..." curl "$SRC_URL" --progress-bar --output "$DL_SRC_PATH" if [ $? -ne 0 ]; then exit 1 fi if [ ! -f "$container_build_blob" ]; then echo "Error: This script requires \"$container_build_blob\"." exit 1 fi else echo "* using existing \"$container_build_blob\" to build the container image" fi cp ../install-minetest-build-deps.sh $docker_image_dir/ # ^ This copy of it is in .gitignore. if [ $? -ne 0 ]; then echo "Error: 'cp ../install-minetest-build-deps.sh $docker_image_dir/' failed." exit 1 fi move_back="false" prerelease_path=~/Downloads/minetest.org/insider-prerelease/linux-minetest-kit-220509.zip if [ ! -f $container_build_blob ]; then if [ -f "$prerelease_path" ]; then move_back="true" echo "mv $prerelease_path $container_build_blob" mv $prerelease_path $container_build_blob if [ $? -ne 0 ]; then echo "* Error: the mv command failed." exit 1 fi fi fi sudo docker build -t $image_name $docker_image_dir code=$? if [ "@move_back" = "@true" ]; then echo "mv \"$prerelease_path\" \"$container_build_blob\"" mv "$container_build_blob" "$prerelease_path" if [ $? -ne 0 ]; then echo "* Warning: the mv command failed." fi fi if [ $code -ne 0 ]; then exit 1 fi else echo "* The container will be built using the existing docker image $image_name" fi cat <) # You must use the container name (as determined using the "ps" subcommand), not the image name. sudo docker container run -it $image_name /bin/bash # ^ Run an interactive terminal (Type 'exit' to exit) # (based on ) sudo docker commit $container_Id $server_finetest_image sudo docker container run --name tmp_test_im -it $server_finetest_image /bin/bash # ^ Transform the container into an image and inspect the internals manually # (based on ). # Then: sudo docker rm --force tmp_test_im sudo docker attach $container_name # ^ Attach your current terminal to a running container (See # ). sudo docker rm --force $container_name # ^ Delete a container by its name. # --force: kill and delete running containers as well. END # sudo docker container run -d --name $image_name unzip xvf $contained_arc -C $contained_repos container_Id=`sudo docker ps -aqf "name=$container_name"` # ^ ONLY works with container_name not image_name cat > /dev/null <. # Therefore: echo "* Creating server image..." sudo docker commit $container_Id $server_finetest_image if [ $? -ne 0 ]; then echo "FAILED (sudo docker commit $container_Id $server_finetest_image)" fi echo "* Running $server_bin_path in container \"$server_container\"" sudo docker container run --name $server_container $server_finetest_image $server_bin_path if [ $? -ne 0 ]; then echo "FAILED (sudo docker container run --name $server_container $server_finetest_image $server_bin_path)" fi # How to use docker-compose (See ): # "1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere." # "2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment." # "3. Run docker compose up and the Docker compose command starts and runs your entire app. You can alternatively run docker-compose up using the docker-compose binary."