Docker学习笔记1

Docker学习笔记


Docker是开发人员和系统管理员使用容器开发,部署和运行应用程序的平台。使用Linux容器部署应用程序称为容器化。它们可以用于轻松部署应用程序。 容器化目前已经越来越受欢迎。
Docker主要包含以下优点:
1.灵活:即使是最复杂的应用也可以集装箱化。
2.轻量级:容器共享主机内核,而不是像虚拟机一样,拥有自己单独的宿主os。
3.可互换:可以即时部署更新和升级。
4.便携式:可以在本地构建,部署到云,并在任何地方运行。
5.可扩展:可以增加并自动分发容器副本。
6.可堆叠:可以垂直和即时堆叠服务。

images(图像)和containers(容器) :

容器是由镜像来启动的。 images是一个可执行包,包含运行应用程序所需的所有内容 - --代码、库、环境变量和配置文件等。

容器是镜像的运行时实例 - 也就是说,容器就是镜像在执行时在内存中的样子(即具有状态的镜像或用户进程)。 您可以使用命令docker ps查看正在运行的容器列表,就像在Linux中一样。

容器在Linux上本机运行,并与其他容器共享主机的内核。 它运行一个独立的进程,不占用任何其他可执行文件的内存,使其轻量级。

Docker学习笔记1
container 容器在Linux上本机运行,并与其他容器共享主机的内核。 它运行一个独立的进程,不占用任何其他可执行文件的内存,使其轻量级。
Docker学习笔记1
VM 相比之下,虚拟机(VM)运行一个完整的“客户”操作系统,通过虚拟机管理程序对主机资源进行虚拟访问。 通常,VM提供的环境比大多数应用程序需要的资源更多。

Docker 在Ubuntu16.04上安装

在新主机上首次安装Docker CE之前,需要设置Docker存储库。 之后,您可以从存储库安装和更新Docker。

  • Update the apt package index :
    $ sudo apt-get update

  • Install packages to allow apt to use a repository over HTTPS :
    sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ software-properties-common

  • Add Docker’s official GPG key :
    $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

  • Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
    $ sudo apt-key fingerprint 0EBFCD88

  • 使用以下命令设置稳定存储库。 即使您还想从边缘或测试存储库安装构建,您始终需要稳定的存储库。 要添加边缘或测试存储库,请在stable之后添加edge或test(或两者)
    sudo add-apt-repository \ "deb [arch=amd64] https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) \ stable"

  • Update the apt package index.
    $ sudo apt-get update

  • ** 安装最新版本的 Docker CE**
    sudo apt-get install docker-ce

  • 验证Dcoker是否安装成功
    $ sudo docker container run hello-world

  • 启动ocker服务
    sudo service docker start

  • 查看Docker版本号
    docker -v
    Docker version 18.09.0, build 4d60db4
    -运行helloworld镜像
    docker run hello-world
    显示如下结果:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/

则Docker安装完毕!!!