The document discusses best practices for using Docker for deploying Node.js applications. It covers creating a Dockerfile and docker-compose.yml file, including setting environment variables, using a non-root user, limiting memory usage, caching layers for faster builds, and volumes for local development versus remote deployment. Automating deployments with tools like Jenkins is also mentioned. The goal is to have repeatable, optimized deployments with a single command and best practices around testing and versioning.
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
Deploy Nodejs on Docker
1. How many…
are using Docker in production?
are using Docker in development?
are here to see if Docker is the right tool for them?
#DesertCodeCamp @wfbutton
2. In this session:
• Docker best practices
• Deploying node.js
• Creating Docker resources
• Performance optimizing
• Repeatable
#DesertCodeCamp @wfbutton
8. …gets a user
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
#DesertCodeCamp @wfbutton
9. …gets and a home
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs
#DesertCodeCamp @wfbutton
10. …gets a production env
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs
ENV NODE_ENV=production
#DesertCodeCamp @wfbutton
17. back to the Dockerfile
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs
ENV NODE_ENV=production
USER nodejs
CMD ["node", "server.js"]
This isn’t bad, and it will work…
but we can improve it!
#DesertCodeCamp @wfbutton
18. What if…
I copied these into the container?
#DesertCodeCamp @wfbutton
19. As a matter of fact…
• it will create the node_modules folder
• thanks to Docker caching and build layers, if
package.json and npm-shrinkwrap.json don’t
change:
• the layer gets re-used
• Result: faster deploys because you don’t have to
wait for npm install to run
#DesertCodeCamp @wfbutton
20. there is a catch…
from node:4.4.7
RUN useradd --user-group --create-home --shell /bin/false
nodejs
ENV HOME=/home/nodejs
ENV NODE_ENV=production
COPY package.json npm-shrinkwrap.json $HOME/app/
RUN chown -R nodejs:nodejs $HOME/*
USER nodejs
RUN npm install
CMD ["node", "server.js"]
#DesertCodeCamp @wfbutton
28. Remember the .:/home?
• The dot is a local reference.
• On a remote server you can’t
reference local folders
• Use a file system reference
local to the Docker host
#DesertCodeCamp @wfbutton
29. Going further
• Deploy script reduces
deployments to a single
command
• While simple to start, they can
grow with your needs
• Imagine new developer on-
boarding
#DesertCodeCamp @wfbutton
30. Hey new guy,
clone the repo and type ‘npm deploy’
#DesertCodeCamp @wfbutton
31. The Keys to the Castle
Don’t be ridiculous, we’re not doing that…
#DesertCodeCamp @wfbutton
33. Testing
• Sadly, still an area where Docker needs work
• Bundle test suite (and test data) into image
• Rely on external integration style tests for validation
#DesertCodeCamp @wfbutton
34. • Goal of using best practices
• Pinned version
• non-root user
• environment variables
• memory limits
• Caching layers for performance
• Locally vs. Remote Deploys
• Single command deployments
• Automated deployments
• Testing
#DesertCodeCamp @wfbutton
35. Try it out.
Use the repo as a basic starter kit.
If it works, awesome!
If it doesn’t, fail fast!
#DesertCodeCamp @wfbutton