Then I had to make a decision whether to stand up an apache server in the container to run the game or to run it as a node app. With a little help from my mate David Balharrie with Express I went for a Node app. You can download the finished source code > AstriodsApp (44 downloads) <
So after making sure the game ran ok under Node, this is what I did to containerise it:
Created a file called Dockerfile in the source folder.
The first line tells Docker to use “alpine” container which is a basic Linux as its base container. Everything else from now on layers on top of alpine.. It could have easily been CoreOS or any other Linux.
We then set a label
We then install a node and a npm as a separate layer
Copy the app into a src directory in the container and set the working directory
We then set npm to install any of the dependencies of the app
Expose port 3000 as this is what the app run on in node.
And finally, tell Docker what to run when it fires up the container.. in our case Node and the App
After creating our Docker file its time to build the container using this command:
$docker image build –t asteroids .
Once the docker container is built we can run an instance of it using this command:
$ docker container run -d –name astr -p 3000:3000 asteroids
If you open a browser and point the url to the name or ip of the docker host :3000 for example http://localhost:3000 you should then see the Astriods game running…. Cool hey?