package.jsonfile that describes your app and its dependencies:
npm install. If you are using
npmversion 5 or later, this will generate a
package-lock.jsonfile which will be copied to your Docker image.
Dockerfilein your favorite text editor
npmbinary. Please note that if you are using
npmversion 4 or earlier a
package-lock.jsonfile will not be generated.
package.jsonfile. This allows us to take advantage of cached Docker layers. bitJudo has a good explanation of this here. Furthermore, the
npm cicommand, specified in the comments, helps provide faster, reliable, reproducible builds for production environments. You can read more about this here.
8080so you'll use the
EXPOSEinstruction to have it mapped by the
CMDwhich defines your runtime. Here we will use
node server.jsto start your server:
Dockerfileshould now look like this:
.dockerignorefile in the same directory as your
Dockerfilewith following content:
Dockerfileand run the following command to build the Docker image. The
-tflag lets you tag your image so it's easier to find later using the
-druns the container in detached mode, leaving the container running in the background. The
-pflag redirects a public port to a private port inside the container. Run the image you previously built:
8080port inside of the container to the port
49160on your machine.
curl(install if needed via:
sudo apt-get install curl):