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 imagesdocker ps = list running contaniers 

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 registrydocker images

Run

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

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

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

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

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

image-20240205211619780

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 .

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

这篇关于Docker 一小时从入门到实战 —— Docker commands | Create your own image | vs VM ... 基本概念扫盲的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/684031

相关文章

Python并行处理实战之如何使用ProcessPoolExecutor加速计算

《Python并行处理实战之如何使用ProcessPoolExecutor加速计算》Python提供了多种并行处理的方式,其中concurrent.futures模块的ProcessPoolExecu... 目录简介完整代码示例代码解释1. 导入必要的模块2. 定义处理函数3. 主函数4. 生成数字列表5.

VS配置好Qt环境之后但无法打开ui界面的问题解决

《VS配置好Qt环境之后但无法打开ui界面的问题解决》本文主要介绍了VS配置好Qt环境之后但无法打开ui界面的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要... 目UKeLvb录找到Qt安装目录中designer.UKeLvBexe的路径找到vs中的解决方案资源

Java Spring 中的监听器Listener详解与实战教程

《JavaSpring中的监听器Listener详解与实战教程》Spring提供了多种监听器机制,可以用于监听应用生命周期、会话生命周期和请求处理过程中的事件,:本文主要介绍JavaSprin... 目录一、监听器的作用1.1 应用生命周期管理1.2 会话管理1.3 请求处理监控二、创建监听器2.1 Ser

Python中OpenCV与Matplotlib的图像操作入门指南

《Python中OpenCV与Matplotlib的图像操作入门指南》:本文主要介绍Python中OpenCV与Matplotlib的图像操作指南,本文通过实例代码给大家介绍的非常详细,对大家的学... 目录一、环境准备二、图像的基本操作1. 图像读取、显示与保存 使用OpenCV操作2. 像素级操作3.

Apache 高级配置实战之从连接保持到日志分析的完整指南

《Apache高级配置实战之从连接保持到日志分析的完整指南》本文带你从连接保持优化开始,一路走到访问控制和日志管理,最后用AWStats来分析网站数据,对Apache配置日志分析相关知识感兴趣的朋友... 目录Apache 高级配置实战:从连接保持到日志分析的完整指南前言 一、Apache 连接保持 - 性

MQTT SpringBoot整合实战教程

《MQTTSpringBoot整合实战教程》:本文主要介绍MQTTSpringBoot整合实战教程,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考... 目录MQTT-SpringBoot创建简单 SpringBoot 项目导入必须依赖增加MQTT相关配置编写

JavaScript实战:智能密码生成器开发指南

本文通过JavaScript实战开发智能密码生成器,详解如何运用crypto.getRandomValues实现加密级随机密码生成,包含多字符组合、安全强度可视化、易混淆字符排除等企业级功能。学习密码强度检测算法与信息熵计算原理,获取可直接嵌入项目的完整代码,提升Web应用的安全开发能力 目录

Redis迷你版微信抢红包实战

《Redis迷你版微信抢红包实战》本文主要介绍了Redis迷你版微信抢红包实战... 目录1 思路分析1.1hCckRX 流程1.2 注意点①拆红包:二倍均值算法②发红包:list③抢红包&记录:hset2 代码实现2.1 拆红包splitRedPacket2.2 发红包sendRedPacket2.3 抢

springboot项目redis缓存异常实战案例详解(提供解决方案)

《springboot项目redis缓存异常实战案例详解(提供解决方案)》redis基本上是高并发场景上会用到的一个高性能的key-value数据库,属于nosql类型,一般用作于缓存,一般是结合数据... 目录缓存异常实践案例缓存穿透问题缓存击穿问题(其中也解决了穿透问题)完整代码缓存异常实践案例Red

Spring Boot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)

《SpringBoot拦截器Interceptor与过滤器Filter深度解析(区别、实现与实战指南)》:本文主要介绍SpringBoot拦截器Interceptor与过滤器Filter深度解析... 目录Spring Boot拦截器(Interceptor)与过滤器(Filter)深度解析:区别、实现与实