Coder Social home page Coder Social logo

docker-browser-server's Introduction

docker-browser-server

Spawn and expose docker containers over http and websockets

npm install -g docker-browser-server

Running the above will expose a command line tool called docker-browser-server. To run the server do

docker-browser-server docker-image-name --port 8080

Make sure you pulled docker-image-name from a docker registry first. Running the above will start the server on port 8080

Visit http://localhost:8080 after to attach to a container using a web browser.

You can also pass --hostNetworking to run the containers in host network mode, meaning the network is not virtualized (may be necessary for p2p connections to work)

Spawn a new container

To spawn a new container create a websocket to the server and pipe it to a docker-browser-console instance

// using browserify
var docker = require('docker-browser-console')
var websocket = require('websocket-stream')

var container = docker()
var socket = websocket('ws://localhost:8080')

container.appendTo(document.body)

socket.pipe(container).pipe(socket)

A demo interface is available if you simply visit http://localhost:8080 after starting the server

Expose filesystem

If you run expose-fs inside your container the containers file system will be exposed using the following rest api

  • GET /files/{container}/{path} Get a file or directory listing
  • PUT /files/{container}/{path} Write a new file with the http body
  • POST /files/{container}/{path} Create a new directory

Expose a http server

When you spawn a new container a special env var called $HOST will be set to a http address. If you listen on port 80 inside the container all requests going to $HOST will be forwarded to this server.

Adventure time

Checkout maxogden/adventure-time for a complete client environment that integrates with docker-browser-server.

The easiest way to create your own workshop is creating a new Dockerfile and inheriting from the mafintosh/docker-browser-adventure image. This will setup expose-fs and install node among other things

FROM mafintosh/docker-adventure-time
RUN npm install -g your-workshop-stuff

Programmatic usage

var server = require('docker-browser-server')

var s = server('mafintosh/dev')

s.on('spawn', function(container) {
  console.log('spawned new container', container.id)
})

s.on('kill', function(container) {
  console.log('killed container', container.id)
})

s.listen(8080)

License

MIT

docker-browser-server's People

Contributors

enxebre avatar mafintosh avatar max-mapper avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

docker-browser-server's Issues

TypeError: Cannot read property 'prototype' of undefined

Getting an error:

❯ docker-browser-server busybox --port 8080
~node_modules/root/index.js:30
Root.prototype.__proto__ = process.EventEmitter.prototype;
                                                ^

TypeError: Cannot read property 'prototype' of undefined
    at Object.<anonymous> (~node_modules/root/index.js:30:49)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)
    at Module.load (internal/modules/cjs/loader.js:628:32)
    at Function.Module._load (internal/modules/cjs/loader.js:555:12)
    at Module.require (internal/modules/cjs/loader.js:666:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at Object.<anonymous> (~node_modules/docker-browser-server/index.js:8:12)
    at Module._compile (internal/modules/cjs/loader.js:759:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:770:10)

Server can't spawn a container

Using with docker-browser-console I get this while trying to start and connect to a docker container from the browser:

Server is listening on port 8080
Spawning new container (w0s7qrj10m3x47vi)
Killing container (w0s7qrj10m3x47vi)

Any thoughts why the container gets killed right after it's created?

not sure how to expose the HTTP server

hi, thanks for this environment, it inspired me to do some hacking.

i would like to substitute the guide presentation to the rendering of a static app that is served by the docker server itself.

In this scenario, it's not clear for me how to :

  1. expose the port my app is served to adventure-time.
  2. link other resources ( db ), as we usually do running the container.

Also, the $HOST variable points to a subdomain i could not reach. i understood it would allow me to reach the dockers http-server at 80 ?

Need a way to limit CPU & Memory per container

When launching a Docker container from the terminal, I can add switches to limit CPU & Memory like this: docker run --cpus=1 --memory=2g -it container

Is there a way to do this with the containers that launch in the browser?

hi~ i find a bug

when i ran

docker pull fedora
sudo node bin.js fedora

then

Server is listening on port 8080
Spawning new container (jd9yvosq4x869a4i)
{ AttachStdin: true,
  AttachStdout: true,
  AttachStderr: true,
  OpenStdin: true,
  StdinOnce: true,
  Cmd: [],
  Tty: true,
  Image: 'fedora',
  ExposedPorts: { '80/tcp': {}, '8441/tcp': {} },
  Env: 
   [ 'CONTAINER_ID=jd9yvosq4x869a4i',
     'HOST=http://jd9yvosq4x869a4i.c.127.0.0.1:8080',
     'PORT=80' ],
  Volumes: {} }
{ [Error: No command specified] status: 500 }
Killing container (jd9yvosq4x869a4i)

however,when i ran

sudo node bin.js ubuntu

it is ok.
my os is ubuntu
could you teach me how to fix it ?

Getting error in index.js file

I'm getting this error when I'm trying to launch container
$ docker-browser-server docker.io/httpd --port 8080
/usr/local/lib/node_modules/docker-browser-server/node_modules/root/index.js:30
Root.prototype.proto = process.EventEmitter.prototype;
^

TypeError: Cannot read property 'prototype' of undefined
at Object. (/usr/local/lib/node_modules/docker-browser-server/node_modules/root/index.js:30:49)
at Module._compile (module.js:660:30)
at Object.Module._extensions..js (module.js:671:10)
at Module.load (module.js:573:32)
at tryModuleLoad (module.js:513:12)
at Function.Module._load (module.js:505:3)
at Module.require (module.js:604:17)
at require (internal/module.js:11:18)
at Object. (/usr/local/lib/node_modules/docker-browser-server/index.js:8:12)
at Module._compile (module.js:660:30)

expose-fs not getting forwarded

I want to create a tutorial based on docker-browser-server and command_line_bootcamp. My problem is that my filesystem seemingly does not get shown. Seems as if expose-fs is unable to connect.

I'm running docker-browser-server as a docker-container:

My baseimage is from here

  • It uses expose-fs
  • It exposes port 8441

When connecting to docker-browser-server a new container gets created successfully (Spawning new container (buj5ijhk4e)), but this container does not map its internal port 8441 to the external port 8441. I guess this is why the frontend does not show any files. Docker maps 8441 to some random port though, which I can curl localhost:12345 on and get the files and paths.

My testing frontend is here: https://monsdar.gitlab.io/bootcamp_test/?id=buj5ijhk4e, based on this repo: https://gitlab.com/monsdar/bootcamp_test

Any idea why this is happening? Is this a port-mapping issue, or am I looking in the wrong direction?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.