Language test environment
This is a test environment for various programming languages (most of the languages found here can be found in this Dockerfile). The purpose of this document is to provide a consistent structure for documenting code snippets, examples, and instructions related to different programming languages. Each section will focus on a specific language and include relevant information such as code examples, explanations, and instructions for running programs.
Dockerfile
Here is a Dockerfile based on a lightweight Linux distribution (Alpine) that includes GCC, Fortran, Java, and several other compilers:
Instructions to Build and Run the Docker Container
Save the Dockerfile: Save the above Dockerfile in a file named
Dockerfile.Build the Docker Image: Open a terminal and navigate to the directory containing the Dockerfile. Run the following command to build the Docker image:
docker build -t multi-compiler-env .This command builds the Docker image and tags it as
multi-compiler-env.Run the Docker Container: After the image is built, run the following command to start a container from the image:
docker run -it multi-compiler-envThis command starts the container and opens an interactive terminal session with the Bash shell. You can now use the installed compilers within the container.
Makefile
Here is a Makefile to build and run the Docker container described in the Dockerfile:
Explanation
IMAGE_NAME: Defines the name of the Docker image.
build: Target to build the Docker image.
run: Target to run the Docker container.
clean: Target to remove the Docker image.
all: Default target that builds and runs the Docker container.
Change shell
To change the shell to sh or zsh in the Docker container, you can use the following command:
Or you could change the CMD in the Dockerfile to use a different shell:
Makefile for Changing the Shell
Here is the updated Makefile to include ways to use sh, zsh, and tcsh as the shell:
Explanation of updated Makefile
MOUNT_CODE: Mounts the
optdirectory to the container to share code between the host and the container.run-sh: Target to run the Docker container with
shshell.run-bash: Target to run the Docker container with
bashshell. (This is the default behavior and the same adrun.)run-zsh: Target to run the Docker container with
zshshell.run-tcsh: Target to run the Docker container with
tcshshell.