Docker-初识Docker(一)

1.1 What is Docker

1.1.1 官网首页

 

https://www.docker.co

 

Modernize your applications, accelerate innovation

Securely build, share and run modern applications anywher

 

安全地构建、共享和运行现代应用程序

 

1.1.2 Docs

 

https://docs.docker.com/

 

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

 

Docker是一个开发、发布和运行应用程序的开放平台。Docker能够将应用程序与基础架构分离,以便快速交付软件。有了Docker,你可以像管理应用程序一样管理你的基础设施。通过利用Docker快速发布、测试和部署代码的方法,可以显著减少编写代码和在生产环境中运行代码之间的延迟。

 

 

1.1.3 不理解,我太难了

 

不妨从一个需求开始 :开发好了一个项目shopping,部署上线

 

  • 远古时代

 

问题 :成本高、部署慢、浪费资源、硬件限制、不利于迁移扩展

 

  • 虚拟化时代

 

优点 :相对利用好资源,相对容易扩展等。

缺点 :虚拟机太重了,一上来占用较多物理资源,移植性差,资源利用率低等。

  • 容器时代

 

 

1.1.4 Docker的优势和应用场景

  1. 有助于Microservices的落地和部署

  2. 充分利用物理机资源,同时能够整合服务器资源

  3. 提高开发效率,测试效率,部署效率,有利于DevOps的落地,CICD

  4. 云原生落地,应用更好地迁移

    ...

 

1.2 What is Image and Container?

 

1.2.1 What is Image?

 

Why docker?->What is a container

 

A Docker container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings.

Docker容器映像是一个轻量级的、独立的、可执行的软件包,包含运行应用程序所需的一切:代码、运行时、系统工具、系统库和设置。

 

1.2.2 What is Container?

 

Why docker?->What is a container

https://www.docker.com/resources/what-container

 

A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another. 

 

容器是一个标准的软件单元,它将代码及其所有依赖项打包,以便应用程序从一个计算环境快速可靠地运行到另一个计算环境

 

1.2.3 Relation between image and container

容器和镜像的关系

 

Container images become containers at runtime and in the case of Docker

containers- images become containers when they run on Docker Engine.

 

类似Class->Java对象的关系.


 

 

1.3 Comparing Containers and Virtual Machines

 

 

Containers and virtual machines have similar resource isolation and allocation benefits, but function differently because containers virtualize the operating system instead of hardware. Containers are more portable and efficient.

 

容器和虚拟机具有类似的资源隔离和分配优势,但功能不同,因为容器虚拟化操作系统而不是硬件。容器更便于携带,效率更高。

 

 

 

 

 

1.4 Docker Engine and Architecture

https://docs.docker.com/engine/docker-overview/

 

 

1.4.1 Docker Engine

 

docker引擎

 

Docker Engine is a client-server application with these major components:

Docker Engine是一个客户端-服务器应用程序,具有以下主要组件:

  • A server which is a type of long-running program called a daemon process (the dockerd command).

    作为守护进程(dockerd命令)长时间运行的服务器。

  • A REST API which specifies interfaces that programs can use to talk to the daemon and instruct it what to do.

    支持REST API,应用程序可以用来与守护进程通信并且指示做什么

  • A command line interface (CLI) client (the docker command).

    客户端支持命令行(CLI)(docker命令)。

 

1.4.2 Docker Architecture

docker架构

 

Docker uses a client-server architecture. The Docker client talks to the Docker daemon, which does the heavy lifting of building, running, and distributing your Docker containers. The Docker client and daemon can run on the same system, or you can connect a Docker client to a remote Docker daemon. The Docker client and daemon communicate using a REST API, over UNIX sockets or a network interface.

 

Docker使用客户端-服务端的架构。Docker客户端与Docker服务端通信,后者负责构建、运行和分发Docker容器。Docker客户端和服务端可以在同一个系统上运行,也可以将Docker客户端连接到远程Docker服务端。Docker客户端和服务端使用一个REST API,通过UNIX套接字或网络接口进行通信。

 

 

 

 

1.5 Install

 

https://docs.docker.com/install/linux/docker-ce/centos/

 

1.5.1 Uninstall old versions

 

卸载旧版本docker引擎

sudo yum remove docker \                  docker-client \                  docker-client-latest \                  docker-common \                  docker-latest \                  docker-latest-logrotate \                  docker-logrotate \                  docker-engine

 

 

1.5.2. Install using the repository

 

Install required packages.   安装必要的依赖

sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2


Use the following command to set up the stable repository.  设置仓库

$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

 

 

 

访问这个地址,使用自己的阿里云账号登录,查看菜单栏左下角,发现有一个镜像加速器: https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors

 

1.5.3. Install Docker Engine

 

sudo yum install docker-ce docker-ce-cli containerd.io

 

1.5.4. Start Docker.

sudo systemctl start docker

 

1.5.5. Set startup 

设置开启启动

sudo systemctl enable docker

1.5.6. 测试docker是否安装成功

docker pull hello-world

docker run --name myhelloworld hello-world

docker pull在哪拉取的镜像?默认是在hub.docker.com, 设置后在阿里云镜像

 

1.6 docker基本体验

 

1.6.1. 创建并运行tomcat容器

 

docker pull tomcatdocker run -d --name my-tomcat -p 9090:8080 tomcat

docker pull tomcat拉取的版本是?  默认是最新的版本,可以在后面指定版本":"

 

1.6.2.  创建mysql容器

docker pull mysqldocker run -d --name my-mysql -p 3301:3306 -e MYSQL_ROOT_PASSWORD=root --privileged mysql

docker 启动的时候增加参数--privileged ,开启特权,可以设置容器里的内核参数。

-d:后台运行

 

1.6.3. 进入到容器里面

docker exec -it containerid /bin/bash

 

1.6.4. 删除docker容器

 

docker rm -f containerId       根据容器Id删除docker rm -f $(docker ps -aq)  遍历所有容器删除

 

 

  1. 6.5  其它命令

查看容器      sudo docker ps -a 停用容器      sudo docker stop [CONTAINER ID ] 启动容器      sudo docker start [CONTAINER ID ] 删除容器      sudo docker rm -f  [CONTAINER ID ] 删除镜像      sudo docker rmi [Image ID]删除所有镜像(删除镜像必须先删除container) sudo docker rmi -f $(docker images)查看镜像的    sudo docker images进入容器      sudo docker exec -it [CONTAINER ID ] /bin/bash(sh)容器日志      sudo docker logs [CONTAINER ID ]宿主机搜索docker镜像 sudo docker images | grep [service name]查询tomcat历史操作  sudo histroy | grep tomcat

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值