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

相关文章

Spring Boot + MyBatis Plus 高效开发实战从入门到进阶优化(推荐)

《SpringBoot+MyBatisPlus高效开发实战从入门到进阶优化(推荐)》本文将详细介绍SpringBoot+MyBatisPlus的完整开发流程,并深入剖析分页查询、批量操作、动... 目录Spring Boot + MyBATis Plus 高效开发实战:从入门到进阶优化1. MyBatis

MyBatis 动态 SQL 优化之标签的实战与技巧(常见用法)

《MyBatis动态SQL优化之标签的实战与技巧(常见用法)》本文通过详细的示例和实际应用场景,介绍了如何有效利用这些标签来优化MyBatis配置,提升开发效率,确保SQL的高效执行和安全性,感... 目录动态SQL详解一、动态SQL的核心概念1.1 什么是动态SQL?1.2 动态SQL的优点1.3 动态S

Pandas使用SQLite3实战

《Pandas使用SQLite3实战》本文主要介绍了Pandas使用SQLite3实战,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学... 目录1 环境准备2 从 SQLite3VlfrWQzgt 读取数据到 DataFrame基础用法:读

Docker镜像pull失败两种解决办法小结

《Docker镜像pull失败两种解决办法小结》有时候我们在拉取Docker镜像的过程中会遇到一些问题,:本文主要介绍Docker镜像pull失败两种解决办法的相关资料,文中通过代码介绍的非常详细... 目录docker 镜像 pull 失败解决办法1DrQwWCocker 镜像 pull 失败解决方法2总

通过Docker Compose部署MySQL的详细教程

《通过DockerCompose部署MySQL的详细教程》DockerCompose作为Docker官方的容器编排工具,为MySQL数据库部署带来了显著优势,下面小编就来为大家详细介绍一... 目录一、docker Compose 部署 mysql 的优势二、环境准备与基础配置2.1 项目目录结构2.2 基

Python实战之屏幕录制功能的实现

《Python实战之屏幕录制功能的实现》屏幕录制,即屏幕捕获,是指将计算机屏幕上的活动记录下来,生成视频文件,本文主要为大家介绍了如何使用Python实现这一功能,希望对大家有所帮助... 目录屏幕录制原理图像捕获音频捕获编码压缩输出保存完整的屏幕录制工具高级功能实时预览增加水印多平台支持屏幕录制原理屏幕

最新Spring Security实战教程之Spring Security安全框架指南

《最新SpringSecurity实战教程之SpringSecurity安全框架指南》SpringSecurity是Spring生态系统中的核心组件,提供认证、授权和防护机制,以保护应用免受各种安... 目录前言什么是Spring Security?同类框架对比Spring Security典型应用场景传统

最新Spring Security实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)

《最新SpringSecurity实战教程之表单登录定制到处理逻辑的深度改造(最新推荐)》本章节介绍了如何通过SpringSecurity实现从配置自定义登录页面、表单登录处理逻辑的配置,并简单模拟... 目录前言改造准备开始登录页改造自定义用户名密码登陆成功失败跳转问题自定义登出前后端分离适配方案结语前言

关于Docker Desktop的WSL报错问题解决办法

《关于DockerDesktop的WSL报错问题解决办法》:本文主要介绍关于DockerDesktop的WSL报错问题解决办法的相关资料,排查发现是因清理%temp%文件夹误删关键WSL文件,... 目录发现问题排查过程:解决方法其实很简单:重装之后再看就能够查到了:最后分享几个排查这类问题的小www.cp

OpenManus本地部署实战亲测有效完全免费(最新推荐)

《OpenManus本地部署实战亲测有效完全免费(最新推荐)》文章介绍了如何在本地部署OpenManus大语言模型,包括环境搭建、LLM编程接口配置和测试步骤,本文给大家讲解的非常详细,感兴趣的朋友一... 目录1.概况2.环境搭建2.1安装miniconda或者anaconda2.2 LLM编程接口配置2