当前位置:   article > 正文

Docker 一小时从入门到实战 —— Docker commands | Create your own image | vs VM ... 基本概念扫盲

Docker 一小时从入门到实战 —— Docker commands | Create your own image | vs VM ... 基本概念扫盲

Docker crash course

1. What and Why of Docker?

2.1 What

image-20240131232702960

2.2 What problem does it solve?

2.2.1 before containers

Development process before containers? If your app uses 10 services, each developer needs to install these 10 services.

image-20240131232953257

Development process:

image-20240131234204271

  • Installations and configurations done directly on server’s OS
  • Dependency version conflicts etc.
  • image-20240131234503249

2.1.2 with containers

Development process with containers? Standardizes process of running any services on any local dev environment.

image-20240131233322529

image-20240131233809511

Development process:

  • Install Docker runtime on the server
  • Run Docker command to fetch and run Docker artifacts.

image-20240131234657955

2. Docker vs Virtual Machines

image-20240201222936730

2.1 Difference

image-20240201223239644

docker

  • contains the OS application layer - vertualize complete OS
  • services and apps installed on top that layer

image-20240201223642154

image-20240201223903860

2.2 Benefits

image-20240201224514428

image-20240201225004644

  • most containers are Linux based
  • Originally built for Linux OS

upgrade –

image-20240201225248641

image-20240201225439201

3. Install docker locally

image-20240201225835186

image-20240201225945915

4. Images vs Containers

image-20240202174026601

image-20240202174304374

image-20240202174335917

	docker images
	docker ps = list running contaniers 
  • 1
  • 2

5. Public and Private Registries

How do we get these images?

image-20240202175312917

image-20240202175753612

image-20240202191255815

6. Main Docker commands - pull,run,start,stop,logs,build

6.1 pull & run

Pull Docker Hub registry (docker.io) is used by default.

	docker pull {name}:{tag} = Pull an image from a registry
	docker images
  • 1
  • 2

Run

	docker run {name}:{tag} = creates a container from given images and starts it
	docker ps
  • 1
  • 2
  • docker generates a random name for the container automatically if you don’t specify one
  • docker pulls image automatically, if it doesn’t find it locally.
	docker -d = runs container in background and prints the container ID
  • 1

you may still want to see the logs,which can be useful for debugging etc.

	docker logs {container} = view logs from service running inside the container.
  • 1

give a name --name

docker run --name web-app -d -p 9000:80 nginx:1.23
  • 1

Port Binding

image-20240202201259784

image-20240202201341689

localhost:80 cannot be reached

image-20240202201434320

only run with additional tag:

image-20240202201657337

image-20240202203541008

	docker stop {container} = stop one or more running containers
  • 1
	-p or --publish = pubish a container's port to the host
	-p {HOST_PORT}:{CONTAINER_PORT}
  • 1
  • 2

all in all

	docker run -d -p 9000:80 niginx:1.23
  • 1

image-20240202230203135

image-20240203180806189

6.2 start & stop

image-20240203180858684

docker ps only list the running containers. To list all containers (stopped and running) by using flag -a or --all

docker ps -a
  • 1

stop

docker stop {containerID}
  • 1

start

docker start {containerID} = start one or more stopped containers
  • 1

logs

docker logs {containerID/NAME}
  • 1

7. Public and private Docker registries

image-20240203225855787

image-20240203234521430

8. Registry vs Repository

image-20240203235721998

image-20240204000022806

image-20240204000125110

9. Create own image (Dockerfile)

image-20240205165439067

image-20240205165757421

9.1 Dockerfile - Build instruction

image-20240205165827894

image-20240205165844694

image-20240205165913517

image-20240205171226680

image-20240205171323341

image-20240205171445885

image-20240205210256610

image-20240205210713734

image-20240205211146261

image-20240205211320662

image-20240205211412241

	CMD ["node", "server.js"]
  • 1

image-20240205211619780

9.2 Build image

	docker build {path} = Builds a Docker image from a Dockerfile
  • 1

Sets a name and optionally a tag in the “name:tag” format

	docker build -t node-app:1.0 .
  • 1

image-20240205214951661

image-20240205215035997

9.3 Run as Docker container

image-20240205215254016

9.4 Docker UI Client

10. Image Versioning

image-20240202191521178

“latest” tag mostly refers to the newest release.

11. Docker Compose

12. Docker Workflow Big Picture

How Docker fits in the complete development and development process?

image-20240205221128201

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/80115
推荐阅读
相关标签
  

闽ICP备14008679号