This image is made for compiling C#, C++, Java, and Golang programs
10K+
This image is made for compiling C#, C++, Java, and Golang programs.
Input: .cs, .cpp, .java and .go.
Output: executable .exe file.
FROM ubuntu:latest
RUN apt-get update
&& apt-get install -y g++ mono-mcs golang openjdk-11-jdk
&& rm -rf /var/lib/apt/lists/*
COPY compile_scripts /compile_scripts
WORKDIR /compile_scripts
CMD ["./compile_and_run.sh"]
if [ "$#" -ne 1 ]; then
echo "Usage: ./compile_and_run.sh <source_file>"
exit 1
fi
source_file=$1
extension="${source_file##.}"
filename=$(basename "$source_file")
filename_without_extension="${filename%.}"
only_path=$(dirname "$source_file")
cp $source_file source.$extension
case $extension in
"cpp")
g++ $source_file -o "$filename_without_extension.exe"
echo "C++ Compilation successful."
;;
"cs")
mcs $source_file -out:"$filename_without_extension.exe"
echo "C# Compilation successful."
;;
"go")
go build -o "$filename_without_extension.exe" $source_file
echo "GO Compilation successful."
;;
"java")
javac source.$extension
java ${source_file%.java}
mv ${source_file%.*}.class "$filename_without_extension.exe"
echo "Java Compilation successful."
;;
*)
echo "Unsupported file extension"
exit 1
;;
esac
Installing the Ubuntu image from PowerShell:
wsl --install
installing docker and binding Options->Resources->WSL integration->Enable Ubuntu
Mounting a local disk "e" (you must write your local disk) in Ubuntu:
ll /mnt/e/
(go to the appropriate section where you need to make a docker)
In case of a reading error compile_and_run.sh use the dos2unix command:
dos2unix /mnt/e/diplom/docker-popvepp/Second/compile_scripts/compile_and_run.sh
Create image:
docker build -t maxxk/compiler_image .
Create Docker Container:
Example: docker run -it -v /local/path/on/host system:/path/inside/container my_container_image
--WSL
docker run --name temporary_container -v /mnt/e/diplom/docker-popvepp/Second/Program.cs:/compile_scripts/Program.cs maxxk/compiler_image bash /compile_scripts/compile_and_run.sh Program.cs
--PowerShell
docker run --name temporary_container -v E:\DIPLOM\docker-popvepp\Second\Program.cs:/compile_scripts/Program.cs maxxk/compiler_image bash /compile_scripts/compile_and_run.sh Program.cs
Copying the received file from Docker Container to a local directory:
Example: decker cp <container_id>:/path/to/program.ехе /local/path/on/host
--WSL
docker cp temporary_container:/compile_scripts/output.exe /mnt/e/diplom/docker-popvepp/Second/
--PowerShell
docker cp temporary_container:/compile_scripts/output.exe E:\DIPLOM\docker-popvepp\Second\
--Using PowerShell
docker run --name temporary_container -v {tb_FilePath.Text}:/compile_scripts/{Path.GetFileName(tb_FilePath.Text)} maxxk/compiler_image bash /compile_scripts/compile_and_run.sh {Path.GetFileName(tb_FilePath.Text)}
&& docker cp temporary_container:/compile_scripts/{Path.GetFileName(tb_FilePath.Text)} {Path.GetDirectoryName(tb_FilePath.Text)}\
&& docker rm temporary_container
tb_FilePath - TextBox (WinForms), contains the path to the desired file .cs, .cpp, ...
Example: E:\FromCodeToProg\Docker\Program.cs
Content type
Image
Digest
sha256:3365d4dbf…
Size
478.8 MB
Last updated
over 2 years ago
docker pull maxxk/compiler_image