1 docker安装
#获取最新版本的docker
wget -qO- https://get.docker.com/ | sh
#或者
apt-get install docker.io
#检查是否安装成功以及版本
docker
docker -V
2 术语介绍
docker三大核心:Repositories(仓库)、Images(镜像)和Container(容器);三者可以互相转换。
- Docker, 平台工具、守护进程
- Image, 镜像,包括应用及系统的数据包
- Container, 容器,虚拟机的运行机制
- Registry, 仓库登记,管理镜像文件
- Docker hub, Docker官方公有仓库
三大核心的关系,如下图所示:
3创建镜像
Docker镜像的创建方式有两种,分别是:
- 基于现有的镜像修改
- 直接创建新镜像
本文介绍基于已有镜像修改的方式,一共分为五步。
3.1 第一步,下载官网的基础镜像
从官网上pull镜像hello-world,并运行
root@apple:/home/kevin/docker# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
Status: Downloaded newer image for hello-world:latest
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.
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
从官网上pull镜像ubuntu,并以交互的方式运行
root@apple:/home/kevin/docker# docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
e0a742c2abfd: Pull complete
486cb8339a27: Pull complete
dc6f0d824617: Pull complete
4f7a5649a30e: Pull complete
672363445ad2: Pull complete
Digest: sha256:84c334414e2bfdcae99509a6add166bbb4fa4041dc3fa6af08046a66fed3005f
Status: Downloaded newer image for ubuntu:latest
root@93a1b9d39683:/#
root@93a1b9d39683:/#
root@93a1b9d39683:/#
root@93a1b9d39683:/#
root@93a1b9d39683:/#