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

Docker crash course

文章目录

  • Docker crash course
  • 1. What and Why of Docker?
    • 2.1 What
    • 2.2 What problem does it solve?
      • 2.2.1 before containers
      • 2.1.2 with containers
  • 2. Docker vs Virtual Machines
    • 2.1 Difference
    • 2.2 Benefits
  • 3. Install docker locally
  • 4. Images vs Containers
  • 5. Public and Private Registries
  • 6. Main Docker commands - pull,run,start,stop,logs,build
    • 6.1 pull & run
    • 6.2 start & stop
  • 7. Public and private Docker registries
  • 8. Registry vs Repository
  • 9. Create own image (Dockerfile)
    • 9.1 Dockerfile - Build instruction
    • 9.2 Build image
    • 9.3 Run as Docker container
    • 9.4 Docker UI Client
  • 10. Image Versioning
  • 11. Docker Compose
  • 12. Docker Workflow Big Picture

1. What and Why of Docker?

2.1 What

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

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.

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

Development process:

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

  • Installations and configurations done directly on server’s OS
  • Dependency version conflicts etc.
  • Docker 一小时从入门到实战 —— Docker commands | Create your own image | vs VM ... 基本概念扫盲_第4张图片

2.1.2 with containers

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

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

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

Development process:

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

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

2. Docker vs Virtual Machines

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

2.1 Difference

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

docker

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

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

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

2.2 Benefits

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

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

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

upgrade –

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

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

3. Install docker locally

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

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

4. Images vs Containers

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

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

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

	docker images
	docker ps = list running contaniers 

5. Public and Private Registries

How do we get these images?

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

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

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

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

Run

	docker run {name}:{tag} = creates a container from given images and starts it
	docker ps
  • 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

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.

give a name --name

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

Port Binding

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

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

localhost:80 cannot be reached

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

only run with additional tag:

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

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

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

all in all

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

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

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

6.2 start & stop

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

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

docker ps -a

stop

docker stop {containerID}

start

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

logs

docker logs {containerID/NAME}

7. Public and private Docker registries

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

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

8. Registry vs Repository

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

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

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

9. Create own image (Dockerfile)

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

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

9.1 Dockerfile - Build instruction

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

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

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

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

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

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

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

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

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

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

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

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

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

9.2 Build image

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

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

	docker build -t node-app:1.0 .

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

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

9.3 Run as Docker container

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

9.4 Docker UI Client

10. Image Versioning

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

“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?

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

你可能感兴趣的:(docker,eureka,容器,云原生,运维,笔记,架构)