images
- recipe
- tech
- runtime
- tools to run code
containers
- output
- 1 image can create multiple container instances
- write server: must have index.js: app.get const port app.listen
- you write images in docker file
- FROM …
- WORKDIR …(similar to
cd)
- COPY package*.json ./ (copy package/package-lock if avaliable)
- RUN npm install (install dependencies)
- need to create .dockerignore to avoid hassle of the next step
node_modules
.env
your browser history
- COPY . . (boom copy everything into container)
- but we don’t want to copy node_modules
- ENV PORT=xxxx (we can set environment variable in docker)
- EXPOSE xxxx
- run the app with
CMD ["npm","start"] (CMD to start the container)
- build image with
docker build -t preferred_image_name .(location you want it to be)
- run container:
docker run -p xxxx:xxxx preferred_image_name
- -p : port forwarding from computer:docker_container
- docker compose
- set up everything in one container is too painful
- multi container application: if your project required backend, database, frontend, go separate them into many containers
- but to do this, you need to run everything all at once, so, you need to connect them somehow
- starts from create
compose.yaml
docker compose up
docker compose down to close
- docker volume
- docker wipe everything (state, data) when we close our containers
- volume: dir that docker can access to save stuffs and share to other containers
- docker build cloud
docker init
- but you can get a basic template with
docker init
compose.yaml
services:
backend:
build: .
ports:
- '9000:9000'
db:
image: postgres:latest
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
volumes:
- postgres_data:/var/lib/postgersql/data
volumes:
postgres_data:
docker commands
- docker —version
- docker exec (run via terminal if you don’t wanna run stuff via docker desktop)
- docker scout : good please do this to find
- in GUI click at running image, click vulnerabilities, then click start analysis
created on: Sat Nov 29 2025