Sign inSign up

maxxk/compiler_image

By maxxk

Updated over 2 years ago

This image is made for compiling C#, C++, Java, and Golang programs

Image
Integration & delivery
Developer tools
Content management system
2

10K+

maxxk/compiler_image repository overview

This image is made for compiling C#, C++, Java, and Golang programs.
Input: .cs, .cpp, .java and .go.
Output: executable .exe file.

File .\Dockerfile:

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"]

File .\compile_scripts\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

Some commands:

  1. Installing the Ubuntu image from PowerShell:
    wsl --install

  2. installing docker and binding Options->Resources->WSL integration->Enable Ubuntu

  3. 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)

  1. 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

  2. Create image:
    docker build -t maxxk/compiler_image .

  3. 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

  4. 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\

All in one (command for integrate with C#)

--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

Tag summary

Content type

Image

Digest

sha256:3365d4dbf

Size

478.8 MB

Last updated

over 2 years ago

docker pull maxxk/compiler_image