- to have a linux container with our app up and running.
- The sourcecode lives in mounted volume on the host, so, that we can directly
Prerequisits
At first, you need to have some tools installed locally on yout machine. Here they are.- node.js installed
- npm installed
- docker installed
$ apt-get install nodejs $ apt-get install npmWe only need node and npm installed, to create a boilerplate app. In your daily works you will only checkout your project.
On windows and mac you can do it like that
https://nodejs.org/en/download/
Install docker
Windows and Mac, follow the instruction under:https://www.docker.com/products/docker#/linux
If you are on ubuntu you can install docker like that:
http://magento2-tuts.blogspot.de/2016/08/install-docker-on-ubuntu-1604.html
Install node sample app
We want to have our node.js sourcecode on the local machine, not in the docker container directly. So we are mounting the workingdirectory into the docker container laterInstall an express and express-generator
$ npm install -g express express-generator
Create an express project
$ express sampleApp
$ npm installThis will generate our skeleton app. in the current folder
Download your docker baseimage
To make things simple, we want to use a predefined "node.js ready" ubuntu image from dockerhub. If you dont know docker hub, take your time to create a an acocunt. you will need it later. https://hub.docker.com/pull your node container
$ docker pull nodeThis will download our working image
Create your appcontainer
Now let's create our contrainer in which our node.js express app will live. We want, that we can browse the app on port 8080 and we want our sourcecode is mounted as a volume to the the docker container in dir "/var/www"This can be done by follwing command
$ docker run -p 8080:3000 -v $(pwd):var/www -w "/var/www" node npm startTo expain that
- -p 8080:3000 -> the host port 8080 will be forwarded to port 3000 on the docker container, so we can reach the container under http://localhost:8080
- -v -> we want to mount a folder on the host as a volume to the container
- $(pwd):var/www -> That means to mount the current dir to "var/www" in the container
- -w "var/www" -> That means to change to "/var/www" on the container.
- npm start -> starts the app in "/var/www"
Test your container
Now you can surf "http://localhost:8080" and you should see your express siteWOW. thats awesome.
But wait. We want to test, how easy it is to edit your sourcecode.
Go to your app directory where your code files lives and edit the index.hbm in the views folder.
Type "Hi there" somewhere in the html code.
Reload your browser.
You will see your changes directly
Keine Kommentare:
Kommentar veröffentlichen