Docker
A containerized software that helps to reproduce environments between systems
- No it works on my machine
Files involved:
- Dockerfile
- .dockerignore
- docker-compose.yml
Dockerfile
Used to orchestrate an image
- The FROM line, tells docker how to initialize (FROM node: , FROM debian:)
- WORKDIR, tells docker where to initiate commands
- RUN, commands ran in terminal (apt-get, npm run install)
- EXPOSE ports
- CMD, used to START the container after building (
CMD ["npm", "start"])- This is not the same as the run command although their both terminal commands
- You can only have ONE CMD per dockerfile
Docker Compose
Orchestrates different docker containers (IE a frontend, backend, and database)
- “multi-container applications”, modularizes different parts and allows the to communicate
- Defined in docker-compose.yml
Best Practices
- Base image matters ALOT (using lastest can be 1gb+). Instead, use minimal images
- -alpine is purpose built for containers (node:22-alpine)
- Cache layers! Do reproducible things FIRST. (ie copy package.json first then install only that, instead of copying the entire workdir at a time)