one line of code at a time
Docker Tutorial for Beginners 정리 본문

What is Docker?
- Docker is a platform for building, running, and shipping applications in a consistent manner
- 내가 만든 프로그램이 다른 컴퓨터나 머신에서 안 돌아가는 경우가 있다. 그 이유로는 (1) one or more files missing, (2) software version mismatch (3) different configuration settings (environment variables are different across machines)
docker-compose up
- docker will automatically download and run dependencies inside an isolated environment called a container
- 다른 기계들에서도 내 애플리케이션이 잘 돌아가게 만들 때 도커가 필요하다.
- 그 애플리케이션을 지울 때도 다른 것과 messing up 하지 않고 그 애플리케이션과 관련된 dependencies만 제거되므로 매우 편리하다.
Virtual Machines vs Containers
- container is an insolated environment for running an application, whereas virtual machine is an abstract of a machine (physical hardware)
- 하나의 machine 위에 여러 개의 virtual machine를 run 시킬 수 있다. 예를 들어, 내 Mac PC에 window와 linux virtual machine을 작동시킬 수 있다. hypervisor라는 도구가 이것을 가능하게 해준다. hypervisor is a software to create and manage virtual machines. 대표적인 hypervisor의 예시로는 VirtualBox, VMware 등이 있다.
- virtual machine에서도 애플리케이션을 따로 관리할 수 있다는 장점이 있다. 그러나 문제가 있는데 (1) Each VM needs a full-lbown OS, (2) Slow to start (entire OS should be loaded just like your computer), (3) Resource intensive (takes actual hardware resources like CPU and memory)
- containers: (1) allow running multiple apps in isolation, (2) are lightweight, (3) share OS of the host, (4) start quickly (5) need less hardware resources
Architecture of Docker
- docker use client-server architecture
- containers share OS of the host. More accurately, all these containers share the kernel of the host
- what is kernel? A kernel manages applications and hardware resources
- every operating system has its own kernel or engine and these kernels have different APIs. that's why we cannot run window application on linux b/c these applications are talking to the kernel of the underlying OS.
Installing Docker

Development Workflow
- dockerize the application by making dockerfile. dockerfile is a plain text file that includes instructions that docker uses to package up the application into an image. this image contains everything our application needs to run.
- our application gets loaded inside a container (도커는 어플리케이션이 컨테이너라는 독립된 공간에서 돌아갈 수 있도록 해다)
- once we have the image, we can push it into a docker registry like docker hub (storage for docker images). 그리고 다른 머신에서 그 애플리케이션을 실행하거나 테스트하고 싶을 때 docker hub에서 이미지를 다운받으면 끝!
Dockerfile
FROM node:alpine
COPY . /app
WORKDIR /app
CMD node app.js
docker build -t hello-docker .

docker run hello-docker
Linux
- docker is build on basic Linux concepts
- Linux is like an English
Linux Distributions
- Ubuntu (most popular linux distribution)
- Debian
- Alpine
- Fedora
- CentOS
Running Ubuntu
docker run ubuntu
docker image를 pull 받지 않고, run 커맨드를 입력하면 도커가 알아서 있는지 없는지 확인하고 없으면 이미지를 다운받아서 컨테이너를 실행시키고 이미지가 있으면 그냥 실행시킨다.

docker ps
# run 되고 있는 컨테이너를 확인할 수 있다
docker ps -a


- shell is a program that takes our commands and passes them to the operating system for execution
- `echo $0`: we can see the location of the shell program
- bash is short for Bourne-Again SHell
- linux is a case sensitive os

Managing packages
- apt: ubuntu를 위한 package manager
apt update
apt install nano
- before installing a package, you should always run `apt update` to update package database and then install packages.
Linux File System
- In Linux, everything is a file.
pwd # print working directory

/# root directory
~# home directory
`cd ~`를 입력하면 home directory로 간다
`cd ..`를 입력하면 root directory로 간다
Manipulating Files and Directories
- 파일을 만들고 싶다면, touch 명령어를 써주면 된다

파일을 제거할 때는 rm, 폴더를 제거할 때는 rm -r

mkdir
touch
rm
rm -r
'개발공부' 카테고리의 다른 글
| Microservices with Spring Boot (Gateway, Discovery, Config server) (0) | 2024.08.11 |
|---|---|
| 컴퓨터 구조와 운영체제 50분만에 핵심 개념 정복하기 영상 정리 (0) | 2024.08.08 |
| 혼자 공부하는 네트워크 저자 50분 특강 정리 (0) | 2024.08.07 |