You can build your image by installing all dependencies (node, npm, your packages
) then copy your code inside and share your working directory, your entrypoint/cmd
should run your node script.
Read this article which will help you understand how to build efficient dockerfile
for node.js
especially. You can also read this from docker's website for general best practices.
Here is a simple docker file to only give you a simple idea how to hookup your code and run simple html page in your machine inside nginx server inside container (you did not install nginx at all in your machine).
Note: this is only to understand the concept
1) Create a new file, name it dockerfile
and add the following content, I tried to give you comments for each line to understand but you can remove those comments if you want.
FROM ubuntu #this is the base image
MAINTAINER Your name
RUN apt-get update #feel free to install and update packages
RUN apt-get install -y nginx #easily as you're in your linux env, you can install nodejs here
COPY . /usr/share/nginx/html/ #share the current content of working directory to nginx folder inside container
ENTRYPOINT [“/usr/sbin/nginx”,”-g”,”daemon off;”] #run nginx server that should display copied files
EXPOSE 80 #expose port 80 to your machine (host)
Notice COPY
where we copied content of your code inside container.
2) Inside the same directory, add index.html and your content inside it
$ echo "hello world" > index.html
3) Build your image and tag/name it MyImage
docker build -t MyImage:latest .
4) Run your container or instance of your image:
docker run -d -p 80:80 MyImage
5) browse http://localhost
For more info. and details, better to check docker's documentation.