[Docker] 00 - What is Docker?
一、资源
【尚硅谷】Docker全套教程 by周阳 on Apr 15, 2019
基于 Go语言实现的云开源项目。
Docker Hub: DockerHub入门
Mesos是什么?
-
学习路线图
二、理念
开发者去构成一个镜像,放在docker上面跑。
为什么快?
软件工作所需的库资源和设置。
但,没有自己的内核,也没有进行硬件虚拟。
三、安装
因为基于go语言,所以最好使用较新的系统和版本。
-
CentOS6.8 安装 Docker
-
Ubuntu 18.04 安装 Docker
Docker Tutorial 1: Docker Installation in Ubuntu 18.04
官方安装文档:https://docs.docker.com/engine/install/ubuntu/
四、架构图
一个image可以创建多个containers。类似于一个class可以实例化为多个“对象”。
五、docker run
先从本地看是否有该镜像;如果没有,就从云下载。
jeff@ThinkPad-T490:docker_study$ sudo 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/
六、基本命令
jeff@unsw-ThinkPad-T490:docker_study$ sudo docker version Client: Docker Engine - Community Version: 19.03.12 API version: 1.40 Go version: go1.13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:45:36 2020 OS/Arch: linux/amd64 Experimental: false Server: Docker Engine - Community Engine: Version: 19.03.12 API version: 1.40 (minimum version 1.12) Go version: go1.13.10 Git commit: 48a66213fe Built: Mon Jun 22 15:44:07 2020 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.2.13 GitCommit: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc: Version: 1.0.0-rc10 GitCommit: dc9208a3303feef5b3839f4323d9beb36df0a9dd docker-init: Version: 0.18.0 GitCommit: fec3683
jeff@unsw-ThinkPad-T490:docker_study$ sudo docker info
Client: Debug Mode: false Server: Containers: 2 Running: 0 Paused: 0 Stopped: 2 Images: 1 Server Version: 19.03.12 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 7ad184331fa3e55e52b890ea95e65ba581ae3429 runc version: dc9208a3303feef5b3839f4323d9beb36df0a9dd init version: fec3683 Security Options: apparmor seccomp Profile: default Kernel Version: 5.4.0-42-generic Operating System: Ubuntu 18.04.5 LTS OSType: linux Architecture: x86_64 CPUs: 8 Total Memory: 31.03GiB Name: unsw-ThinkPad-T490 ID: OT5L:TWN2:W3WH:WIQL:7NFV:QQWT:24PD:RUSG:LG4L:34SD:ZRT4:R3MR Docker Root Dir: /var/lib/docker Debug Mode: false Registry: https://index.docker.io/v1/ Labels: Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false WARNING: No swap limit support
Ref: 修改 Docker 的默认存储路径
-
docker images
如下,只有一个image;镜像是分层的。
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 7 months ago 13.3kB
OPTIONS说明:
-
docker search
搜索的是云(docker hub)上的全部的!
-s 30 点赞数;
--no-trunc 显示完整的镜像描述;
--automated 只列出automated build类型的镜像;
jeff@ThinkPad-T490:docker_study$ sudo docker search hello-world
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
hello-world Hello World! (an example of minimal Dockeriz… 1277 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 147
tutum/hello-world Image to test docker deployments. Has Apache… 73 [OK]
dockercloud/hello-world Hello World! 19 [OK]
-
docker pull
拉下来一个image,例如tomcat。
$ sudo docker pull tomcat
Using default tag: latest latest: Pulling from library/tomcat d6ff36c9ec48: Pull complete c958d65b3090: Pull complete edaf0a6b092f: Pull complete 80931cf68816: Pull complete bf04b6bbed0c: Pull complete 8bf847804f9e: Pull complete fa776a6e7e37: Pull complete 586534165c2f: Pull complete 0f6d126a6962: Pull complete 9f3317edffb3: Pull complete Digest: sha256:9de2415ccf10fe8e5906e4b72eda21649a7a1d0b88e9111f8409062599f3728e Status: Downloaded newer image for tomcat:latest docker.io/library/tomcat:latest
-
docker rmi
docker rmi -f $(docker images -qa) 全面的批量删除。
jeff@ThinkPad-T490:docker_study$ sudo docker rmi -f hello-world Untagged: hello-world:latest Untagged: hello-world@sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5 Deleted: sha256:bf756fb1ae65adf866bd8c456593cd24beb6a0a061dedf42b26a993176745f6b jeff@ThinkPad-T490:docker_study$ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE tomcat latest 2ae23eb477aa 2 weeks ago 647MB
以上便是“镜像”的相关命令,下一讲,容器的相关命令。