Created: 2023-03-2710:40
What Is Docker?:
consistently build run and ship applications
- containers should contain everything that your application needs to run
- package up everything that is needed
- able to run anywhere that runs docker
- Isolated environments for applications to run
Problems with VMs
aka reasons containers are better
- each VM needs a full copy of an OS
- slow to start
- resource intensive
The Architecture of Docker
understanding how docker works
- client/server model
- container & docker-engine
- communication via REST API
- all containers share the kernel of the host OS
- docker on mac uses a lightweight vm of Linux
Dev Workflow With Docker
- Dockerfile
- plaintext file
- Instructions to package the application into an image
- Images contain
- cut-down OS
- runtime env
- application files
- third-party files
- env vars
- tell docker to start the container using the image
docker run ...
Docker In Action
- make application dir & cd to that dir
mkdir hello-docker; cd hello-docker
- create an “application” file
app.js
- add application code to file
- Instructions:
- start with OS
- Install Node
- Copy app files
- run node app.js
Building a Dockerfile
- start with the base image
FROM node:alpine
- copy app files
COPY . /app
- set working dir in container
WORKDIR /app
- run the app
CMD node app.js
- list images with
docker image ls
References:
- https://www.youtube.com/watch?v=pTFZFxd4hOI