Dockerizing a Node.js web app
- Part1 建立 Dockerfile
- Part2 Docker Compose 的使用
you can create a new project based on docker-nodejs-tutorial by doing the following:
$ git clone https://github.com/andy6804tw/docker-nodejs-tutorial.git
$ cd docker-nodejs-tutorial
When that's done, install the project dependencies.You can use npm or yarn(recommended) for dependency management。
$ npm install
After completing the installation step, you're ready to start the project!
script | Description |
---|---|
start | Serves your app at localhost:8080 |
You can using docker iamge access this project !
Pull Docker image from Docker Hub.
$ docker pull andy6804tw/docker-nodejs-tutorial
Running your image with -d runs the container in detached mode, leaving the container running in the background. The -p flag redirects a public port to a private port inside the container. Run the image you previously built.
$ docker run -p 3000:8080 -d andy6804tw/docker-nodejs-tutorial
Docker mapped the 8080 port inside of the container to the port 3000 on your machine.
$ curl -i localhost:3000