#!/bin/bash # See https://nextbreakpoint.com/posts/article-compile-code-with-docker.html # sudo docker build -t lmk-devuan-chimaera-img dyne/devuan:chimaera docker_path="`sudo bash -c 'command -v docker'`" ENABLE_CLASSIC=false for var in "$@" do if [ "@$var" = "@--classic" ]; then ENABLE_CLASSIC=true fi done if [ ! -f "$docker_path" ]; then cat < or Docker's own documentation at . END fi # container_name="linux-minetest-kit-build-libraries-devuan-chimaera" # ^ This is no longer necessary since the IMAGE does the building (build was moved to Dockerfile) source lmk.devuan-chimaera.rc if [ $? -ne 0 ]; then exit 1; fi if [ ! -d "$docker_libraries_image_dir" ]; then echo "* $0 must run from the directory containing the container image directory: $docker_libraries_image_dir" exit 1 fi # ^ docker_libraries_image_dir has to be in the same directory as Dockerfile or # the COPY command in the Dockerfile won't work. source $docker_libraries_image_dir/lmk.rc if [ $? -ne 0 ]; then exit 1 fi if [ "@$DL_SRC_PATH" = "@" ]; then # DL_SRC_PATH="$HOME/Downloads/$DL_SRC_NAME" DL_SRC_PATH="$docker_libraries_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 $library_image > /dev/null sudo docker image inspect $library_image --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_libraries_image_dir" ]; then echo "Error: \"$docker_libraries_image_dir\" (docker_libraries_image_dir for storing $SRC_URL) doesn't exist in \"`pwd`\"." exit 1 fi echo "* building image $library_image..." 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_libraries_image_dir/ # ^ This copy of it is in .gitignore. if [ $? -ne 0 ]; then echo "Error: 'cp ../install-minetest-build-deps.sh $docker_libraries_image_dir/' failed." exit 1 fi move_back="false" 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 $library_image $docker_libraries_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 $library_image" fi cat <) # You must use the container name (as determined using the "ps" subcommand), not the image name. sudo docker container run -it $library_image /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 $library_image unzip xvf $contained_arc -C $contained_repos container_Id=`sudo docker ps -aqf "name=$container_name"` # ^ ONLY works with container_name not library_image cat > /dev/null <. # Therefore: # echo "* Creating image \"$server_finetest_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 # ^ Build the server as a separate step instead (see further up) # 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."