Sign inSign up

rh02/rpi-node2

By rh02

Updated almost 9 years ago

automated build used integer service

Image
0

821

rh02/rpi-node2 repository overview

rpi-node

本场景继续探索如何构建 Docker 容器和自动化部署您的应用程序。这个案例将介绍如何在容器中部署一个 Node.js 应用程序。

In this case, an ideal directory would be /src/app as the environment user has read/write access to this directory.

Base Image

Define a working directory using WORKDIR <directory> to ensure that all future commands are executed from the directory relative to our application.

FROM node
RUN mkdir -p /src/app
WORKDIR /src/app

NPM Install

Install the dependencies required to run the application

COPY package.json /src/app/package.json
RUN npm install

Configuring Application

We can copy the entire directory where our Dockerfile is using COPY . <dest dir>. Once the source code has been copied, the ports the application requires to be accessed is defined using EXPOSE <port>. Finally, the application needs to be started. Once neat trick when using Node.js is to use the npm start command. This looks in the package.json file to know how to launch the application saving duplication of commands.

COPY . /src/app
EXPOSE 3000
CMD [ ”npm”, ”start” ]

Building and Launching Container

To launch your application inside the container you first need to build an image.

The command to build the image is

docker build -t my-nodejs-app .

The command to launch the built image is

docker run -d –name my-running-app -p 3000:3000 my-nodejs-app

Tag summary

Content type

Image

Digest

Size

259.2 MB

Last updated

almost 9 years ago

docker pull rh02/rpi-node2