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

Docker crash course

文章目录

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

1. What and Why of Docker?

2.1 What

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.

Development process:

  • Installations and configurations done directly on server's OS
  • Dependency version conflicts etc.

2.1.2 with containers

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

Development process:

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

2. Docker vs Virtual Machines

2.1 Difference

docker

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

2.2 Benefits

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

upgrade --

3. Install docker locally

4. Images vs Containers

bash 复制代码
	docker images
	docker ps = list running contaniers 

5. Public and Private Registries

How do we get these images?

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

6.1 pull & run

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

bash 复制代码
	docker pull {name}:{tag} = Pull an image from a registry
	docker images

Run

bash 复制代码
	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.
bash 复制代码
	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.

bash 复制代码
	docker logs {container} = view logs from service running inside the container.

give a name --name

bash 复制代码
docker run --name web-app -d -p 9000:80 nginx:1.23

Port Binding

localhost:80 cannot be reached

only run with additional tag:

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

all in all

bash 复制代码
	docker run -d -p 9000:80 niginx:1.23

6.2 start & stop

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

bash 复制代码
docker ps -a

stop

bash 复制代码
docker stop {containerID}

start

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

logs

docker logs {containerID/NAME}

7. Public and private Docker registries

8. Registry vs Repository

9. Create own image (Dockerfile)

9.1 Dockerfile - Build instruction

bash 复制代码
	CMD ["node", "server.js"]

9.2 Build image

bash 复制代码
	docker build {path} = Builds a Docker image from a Dockerfile

Sets a name and optionally a tag in the "name:tag" format

bash 复制代码
	docker build -t node-app:1.0 .

9.3 Run as Docker container

9.4 Docker UI Client

10. Image Versioning

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

相关推荐
-$_$-1 分钟前
【黑马点评】 使用RabbitMQ实现消息队列——1.Docker与RabbitMQ环境安装
分布式·docker·rabbitmq
芯的一天3 分钟前
windows下DockerDesktop命令行方式指定目录安装
windows·docker
学思之道23 分钟前
给Linux操作系统命令取个别名
linux·运维·经验分享·学习方法
s_little_monster28 分钟前
【QT】QT入门
数据库·c++·经验分享·笔记·qt·学习·mfc
dong_beijing1 小时前
GO语言工程构建示例-mac和linux适用
linux·运维·服务器
先生沉默先1 小时前
Unity WebGL使用nginx作反向代理处理跨域,一些跨域的错误处理(添加了反向代理的配置依旧不能跨域)
运维·nginx·webgl
是芽芽哩!1 小时前
【Kubernetes】常见面试题汇总(五十八)
云原生·容器·kubernetes
alfiy1 小时前
Elasticsearch学习笔记(六)使用集群令牌将新加点加入集群
笔记·学习·elasticsearch
帅气的人1231 小时前
使用 docker-compose 启动 es 集群 + kibana
elasticsearch·docker
爱学的小涛1 小时前
【NIO基础】基于 NIO 中的组件实现对文件的操作(文件编程),FileChannel 详解
java·开发语言·笔记·后端·nio