Skip to content

A Server program that allows creation, deployment of Ubuntu Docker containers in the server side, allowing communication with the client through TCP sockets.

Notifications You must be signed in to change notification settings

gclkaze/DockerServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DockerServer - Development

The DockerServer is a REST API server built with Golang's gin that:

  1. allows the creation & execution of Docker ubuntu containers on-demand,
  2. allows the communication between a client and the deployed docker container through socket communication between the server and the client,
  3. supports writing files inside the Docker containers after a POST REST request, where the server obtains the submitted file and then copying it in the container,
  4. supports retrieving files from the Docker container back to client through the host machine,
  5. safely cleaning up the docker containers on-demand and keeping track of orphan sessions. The sessions and the files do not persist.

Purpose

Needed to be able to spawn Ubuntu containers on demand in order to execute various terminal based commands without needed to care about "malicious commands" like "rm -rf *" that would be issued by an evil user.

By building a Docker server that keeps track of the docker containers running, and providing to the user an environment that could do as he/she pleases without the fear of impacting the host machine where the actual server is running.

Technique

The communication between the executed docker container and the client is by opening a TCP Unix socket and allowing the client to send commands to the Docker Server which are passed to the running Docker container. The stdout then is redirected back to the client. Then the client can issue another unix command/program execution as long as the socket is open and the docker container is running.

Configuration

Under dockerserver/resources, the file application.properties exists.

workingDirectory= #The working directory
jobsPrefix= #Spawned container name prefix
host= #Hostname of the DockerServer instance
port= #Port of the DockerServer instance
wsFolder= #Default workspace folder that is the current working directory of all spawned Docker instances

Requirements

docker, golang

Build it through Makefile

make build

REST API

1. POST /create

Creates a new Docker container session and returns a listener's network address that can be used from the client in order to listen to the stdout of the newly created Docker container.

Parameter (passed in the request's Header for now)

ProgramId: string, a unique id to be assigned to the freshly made Docker container.

Response:

{
  "socket": "192.0.2.1:25",
}

2. POST /stop

Stops the session (if it exists) that is assigned to the programId parameter value.

Parameter (passed in the request's Header for now)

ProgramId: string, a unique id to be assigned to the running made Docker container.

Response:

200 (OK) or 500 (Internal Server Error)

3. POST /writeFile

Writes the submitted data to a file with a specific file name (Filename) inside a running container associated with the value of the ProgramId parameter.

Parameters (passed in the request's Header for now)

  1. ProgramId: string, a unique id associated with the running made Docker container.
  2. Filename: the name of the new file inside the Docker container
  3. Post body: the data to be written in the file

Response:

200 (OK) or 500 (Internal Server Error)

4. GET /getFile

Gets the data of a file that exists inside a running Docker container associated with a programId.

Parameters (passed in the request's Header for now)

  1. ProgramId: string, a unique id associated with the running made Docker container.
  2. Filename: the name of the new file inside the Docker container

Response:

The read file data-content.

About

A Server program that allows creation, deployment of Ubuntu Docker containers in the server side, allowing communication with the client through TCP sockets.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

  •  

Packages

No packages published

Contributors 2

  •  
  •