本场景继续探索如何构建 Docker 容器和自动化部署您的应用程序。这个案例将介绍如何在容器中部署一个 Node.js 应用程序。
In this case, an ideal directory would be /src/app as the environment user has read/write access to this directory.
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
Install the dependencies required to run the application
COPY package.json /src/app/package.json
RUN npm install
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” ]
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
Content type
Image
Digest
Size
259.2 MB
Last updated
almost 9 years ago
docker pull rh02/rpi-node2