Skip to content

Instantly share code, notes, and snippets.

@Clivern
Last active December 11, 2021 23:02
Show Gist options
  • Save Clivern/e3e6dc19b4b627db14345a30839a0d96 to your computer and use it in GitHub Desktop.
Save Clivern/e3e6dc19b4b627db14345a30839a0d96 to your computer and use it in GitHub Desktop.

Setup Docker

$ apt-get update
$ apt-get install docker.io -y
$ systemctl enable docker

Python

  1. Setup
$ mkdir -p /etc/pindo/ab8cb4fe-cd08-4a55-8444-2cdcd23d3492
$ echo "python /code/run.py" > /etc/pindo/ab8cb4fe-cd08-4a55-8444-2cdcd23d3492/exec.sh
$ chmod +x /etc/pindo/ab8cb4fe-cd08-4a55-8444-2cdcd23d3492/exec.sh
  1. Create the Code Snippet /etc/pindo/ab8cb4fe-cd08-4a55-8444-2cdcd23d3492/run.py
if __name__ == '__main__':
    print("Hello World")
  1. Create runner.py file to create container and run the file.
import docker

if __name__ == '__main__':
    client = docker.from_env()

    print(client.containers.run(
        "python:3.8",
        "bash /code/exec.sh",
        volumes={'/etc/pindo/ab8cb4fe-cd08-4a55-8444-2cdcd23d3492': {'bind': '/code', 'mode': 'rw'}}
    ))

Ruby

  1. Setup
$ mkdir -p /etc/pindo/286aabd5-9271-4985-a04e-6abedaab09dd
$ echo "ruby /code/run.rb" > /etc/pindo/286aabd5-9271-4985-a04e-6abedaab09dd/exec.sh
$ chmod +x /etc/pindo/286aabd5-9271-4985-a04e-6abedaab09dd/exec.sh
  1. Create the Code Snippet /etc/pindo/286aabd5-9271-4985-a04e-6abedaab09dd/run.rb
puts "Hello World"
  1. Create runner.py file to create container and run the file.
import docker

if __name__ == '__main__':
    client = docker.from_env()

    print(client.containers.run(
        "ruby:3.0",
        "bash /code/exec.sh",
        volumes={'/etc/pindo/286aabd5-9271-4985-a04e-6abedaab09dd': {'bind': '/code', 'mode': 'rw'}}
    ))

PHP

  1. Setup
$ mkdir -p /etc/pindo/85de04dd-2059-4bd8-aa2b-7d40998183e3
$ echo "php /code/run.php" > /etc/pindo/85de04dd-2059-4bd8-aa2b-7d40998183e3/exec.sh
$ chmod +x /etc/pindo/85de04dd-2059-4bd8-aa2b-7d40998183e3/exec.sh
  1. Create the Code Snippet /etc/pindo/85de04dd-2059-4bd8-aa2b-7d40998183e3/run.php
<?php

echo "Hello World\n";
  1. Create runner.py file to create container and run the file.
import docker

if __name__ == '__main__':
    client = docker.from_env()

    print(client.containers.run(
        "php:7.4",
        "bash /code/exec.sh",
        volumes={'/etc/pindo/85de04dd-2059-4bd8-aa2b-7d40998183e3': {'bind': '/code', 'mode': 'rw'}}
    ))

Go

  1. Setup
$ mkdir -p /etc/pindo/2533e7c6-9fd5-4b5c-9632-1da6e919ae4a
$ echo "cd /code
go build run.go
./run" > /etc/pindo/2533e7c6-9fd5-4b5c-9632-1da6e919ae4a/exec.sh
$ chmod +x /etc/pindo/2533e7c6-9fd5-4b5c-9632-1da6e919ae4a/exec.sh
  1. Create the Code Snippet /etc/pindo/2533e7c6-9fd5-4b5c-9632-1da6e919ae4a/run.go
package main

import "fmt"

func main() {
    fmt.Println("Hello World")
}
  1. Create runner.py file to create container and run the file.
import docker

if __name__ == '__main__':
    client = docker.from_env()

    print(client.containers.run(
        "golang:1.17",
        "bash /code/exec.sh",
        volumes={'/etc/pindo/2533e7c6-9fd5-4b5c-9632-1da6e919ae4a': {'bind': '/code', 'mode': 'rw'}}
    ))

Rust

$ mkdir -p /etc/pindo/4b982684-e108-4e7a-a95c-f41d269a7026
$ echo "cd /code
rustc run.rs
./run" > /etc/pindo/4b982684-e108-4e7a-a95c-f41d269a7026/exec.sh
$ chmod +x /etc/pindo/4b982684-e108-4e7a-a95c-f41d269a7026/exec.sh
  1. Create the Code Snippet /etc/pindo/4b982684-e108-4e7a-a95c-f41d269a7026/run.rs
fn main() {
    println!("Hello, world!");
}
  1. Create runner.py file to create container and run the file.
import docker

if __name__ == '__main__':
    client = docker.from_env()

    print(client.containers.run(
        "rust:1.57.0",
        "bash /code/exec.sh",
        volumes={'/etc/pindo/4b982684-e108-4e7a-a95c-f41d269a7026': {'bind': '/code', 'mode': 'rw'}}
    ))

Java

$ mkdir -p /etc/pindo/447c1b5b-8332-435a-a815-9c2a5acbec26
$ echo "cd /code
javac Run.java
java Run" > /etc/pindo/447c1b5b-8332-435a-a815-9c2a5acbec26/exec.sh
$ chmod +x /etc/pindo/447c1b5b-8332-435a-a815-9c2a5acbec26/exec.sh
  1. Create the Code Snippet /etc/pindo/447c1b5b-8332-435a-a815-9c2a5acbec26/Run.java
public class Run {
    public static void main(String args[]) {
      System.out.println("Hello World!");
    }
}
  1. Create runner.py file to create container and run the file.
import docker

if __name__ == '__main__':
    client = docker.from_env()

    print(client.containers.run(
        "openjdk:11",
        "bash /code/exec.sh",
        volumes={'/etc/pindo/447c1b5b-8332-435a-a815-9c2a5acbec26': {'bind': '/code', 'mode': 'rw'}}
    ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment