首页 > 其他分享 >Docker 基本概念

Docker 基本概念

时间:2024-08-21 16:50:10浏览次数:11  
标签:container image 基本概念 镜像 run docker Docker

Container (容器)

容器的特点:

  1. Self-contained. Each container has everything it needs to function with no reliance on any pre-installed dependencies on the host machine.
  2. Isolated. Since containers are run in isolation, they have minimal influence on the host and other containers, increasing the security of your applications.
  3. Independent. Each container is independently managed. Deleting one container won't affect any others.
  4. Portable. Containers can run anywhere! The container that runs on your development machine will work the same way in a data center or anywhere in the cloud!

容器和虚拟机的区别 Containers versus virtual machines (VMs)

Without getting too deep, a VM is an entire operating system with its own kernel, hardware drivers, programs, and applications. Spinning up a VM only to isolate a single application is a lot of overhead.

A container is simply an isolated process with all of the files it needs to run. If you run multiple containers, they all share the same kernel, allowing you to run more applications on less infrastructure.

Using VMs and containers together

Quite often, you will see containers and VMs used together. As an example, in a cloud environment, the provisioned machines are typically VMs. However, instead of provisioning one machine to run one application, a VM with a container runtime can run multiple containerized applications, increasing resource utilization and reducing costs.

容器相关命令

docker run -d -p 8080:80 docker/welcome-to-docker
docker ps
docker ps -a
docker stop

Image (镜像)

A container image is a standardized package that includes all of the files, binaries, libraries, and configurations to run a container.

镜像是各种文件的集合。

镜像的两个特点:

  1. Images are immutable. Once an image is created, it can't be modified. You can only make a new image or add changes on top of it. (镜像是不可修改的)

  2. Container images are composed of layers. Each layer represented a set of file system changes that add, remove, or modify files. (镜像由一些文件系统更改的层组成)

镜像相关命令

docker search docker/welcome-to-docker
docker pull docker/welcome-to-docker
docker image ls
docker images
docker image history docker/welcome-to-docker
docker image history docker/welcome-to-docker --no-trunc

注意:docker image history 命令是显示镜像的层,这个真没想到。

Registry

Registry 一般指 Docker Hub, 也可以有自建 Registry 。
Repository 是一些相关镜像的集合,可以理解为一个文件夹

镜像生成打标签相关命令

docker build -t <YOUR_DOCKER_USERNAME>/docker-quickstart .
docker tag <YOUR_DOCKER_USERNAME>/docker-quickstart <YOUR_DOCKER_USERNAME>/docker-quickstart:1.0
docker push <YOUR_DOCKER_USERNAME>/docker-quickstart:1.0

docker image tagdocker tag 可以给镜像打版本标签。

Docker Compose

在 Docker Compose 一节中介绍了运行 todo list 应用的过程,具体在 Docker 入门教程Develop with containers 一节有叙述,这里偷懒不再写了。另外用到的命令记录下来,作个备忘:

docker compose up -d --build
docker compose down
docker compose down --volumes

至此,基本概念一篇草草结束!

作为初学者和使用者,阅读文档到此已经基本了解 Docker 的静态组成模块,并产生了包括本篇一共三篇笔记。

按顺序其他两篇传送门:

标签:container,image,基本概念,镜像,run,docker,Docker
From: https://www.cnblogs.com/hexff/p/18371541

相关文章

  • docker安装gitlab
    1、获取gitlab镜像#gitlab-ce为稳定版本,不填写版本默认pull最新latest版本dockerpullgitlab/gitlab-ce2、运行gitlabdockerrun-d\-p443:443\-p80:80\-p222:22\--namegitlab\--restartalways\-v/data/gitlab/config:/etc/gitlab\-v/data/gitl......
  • Docker快速入门 01 安装、部署环境
    1.简介和安装1.1简介Docker是一个应用打包、分发、部署的工具。打包:需要的环境变成一个“安装包”。分发:将“安装包”上传到云端,供他人获取。部署:将“安装包”下载下来后直接快速搭建运行环境。通俗讲就是轻量级的虚拟机,只虚拟需要的运行环境。1.2安装这里以Docker......
  • Docker快速入门 02 构建镜像
    本文以PythonWeb(Flask)小项目构建Docker镜像1.准备项目确保PythonWeb项目已准备好项目目录结构my-python-app/│├──app.py├──requirements.txt└──Dockerfileapp.py:Flask应用的主文件。fromflaskimportFlaskapp=Flask(__name__)@app.ro......
  • Docker的安装与镜像配置
           小编目前大一,刚开始着手学习SSM,小编会把每个框架都整理成知识点发布出来。如果你也同时在学习SSM的话,不妨看看我做的这个笔记。我认为同为初学者,我把我对知识点的理解以这种代码加观点的方式分享出来不仅加深了我的理解,或许在某个时候对你也有所帮助,同时也欢迎......
  • docker中间件搭建
    1.docker搭建nacos集群2.2.3run-d-p8848:8848-p9848:9848-p9849:9849--restart=always--network=host-eNACOS_AUTH_ENABLE=true-eNACOS_AUTH_TOKEN=T20230703zxcvbnmasdfghjklqwertyuioT20230703zxcvbnmasdfghjklqwertyuio-eNACOS_AUTH_IDENTITY_KEY=admin20......
  • Docker无法运行java虚拟机报错There is insufficient memory for the Java Runtime
    镜像导入到docker后无法启动容器的问题,但是上传到别的服务器上面又可以正常启动容器,报错信息如下:#ThereisinsufficientmemoryfortheJavaRuntimeEnvironmenttocontinue.#CannotcreateGCthread.Outofsystemresources.#Cannotsavelogfile,dumptoscree......
  • docker部署宝塔面板
    环境准备:系统rocky:9.2部署流程:1.安装dockerdnf-yinstallyum-utilsyum-config-manager--add-repohttp://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo#阿里源dnf-yinstalldocker-ce#自行配置镜像加速#启动服务systemctlenabledo......
  • 安装Docker
    官方网址=>https://www.docker.com/下载安装安装完毕之后,启动服务=>直接搜索服务即可检查Hyper-V是否安装路径在=>控制面板=>程序=>启用或关闭Windows功能,如下图如果没有Hyper选项,则新建文件HyPer.cmdpushd"%~dp0"dir/b%SystemRoot%\servicing\Packa......
  • Docker部署jumpserver
    1.JumpServer概述JumpServer是全球首款完全开源的堡垒机,使用GNUGPLv2.0开源协议,是符合4A的专业运维审计系统。JumpServer使用Python/Django进行开发,遵循Web2.0规范,配备了业界领先的WebTerminal解决方案,交互界面美观、用户体验好。JumpServer采纳分布式架......
  • XSS 基本概念和原理介绍
    XSS基本概念和原理介绍基本概念跨站脚本攻击XSS(CrossSiteScripting),为了不和层叠样式表(CascadingStyleSheets,CSS)的缩写混淆,故将跨站脚本攻击缩写为XSS。恶意攻击者往Web页面里插入恶意JavaScript代码,当用户浏览该页面时,嵌入在Web里面的JS代码会被解......