MYF

Get Started, Part 1: Orientation and setup

参考文档:Get Started, Part 1: Orientation and setup

Docker概念

def: Docker是一个为开发者和系统管理员开发、部署、运行应用程序所搭建的平台。

Images and Containers

一个container通过运行一个image来启动。Image是一个可执行的包,这个包中包含了应用程序所需的所有东西,包括代码、运行环境、库、环境变量、配置文件。Container是一个image的运行实例,也就是image在内存中的形态或者说是一个用户进程,你可以列出一系列containers使用指令docker ps

Container和虚拟机

一个container在Linux本机运行,与其他container共同使用系统的kernel。他运行一个独立的进程,不额外占用内存,使他更lightweight。相比之下,一个虚拟机运行一个完整的操作系统,通过虚拟访问来访问主机资源。总的来说,虚拟机提供了的资源比应用程序需要的更多。

Test Docker version

1
2
[root@digitalocean ~]# docker --version
Docker version 17.12.1-ce, build 7390fc6

使用docker version(而非docker --verion)或者docker info查看更多docker安装的信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[root@digitalocean ~]# docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:15:20 2018
OS/Arch: linux/amd64

Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.9.4
Git commit: 7390fc6
Built: Tue Feb 27 22:17:54 2018
OS/Arch: linux/amd64
Experimental: false
[root@digitalocean ~]# docker info
Containers: 1
Running: 0
Paused: 0
Stopped: 1
Images: 1
Server Version: 17.12.1-ce
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9b55aab90508bd389d7654c4baf173a981477d55
runc version: 9f9c96235cc97674e935002fc3d78361b696a69e
init version: 949e6fa
Security Options:
seccomp
Profile: default
Kernel Version: 4.15.7-1.el7.elrepo.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 986.4MiB
Name: digitalocean
ID: 2353:E4CP:TW4X:5GBF:2QGP:HNS3:5YUY:H4GV:XQ6S:SWDK:UCZD:SN7P
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

为了减少权限问题,使用sudo或者将当前user加入docker的group

Test Docker Installation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
[root@digitalocean ~]# 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://cloud.docker.com/

For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/

列出本机上的所有image

1
docker image ls

列出本机上的container

1
docker container ls -a

Recap and cheat sheet

命令总结

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
## List Docker CLI commands
docker
docker container --help

## Display Docker version and info
docker --version
docker version
docker info

## Excecute Docker image
docker run hello-world

## List Docker images
docker image ls

## List Docker containers (running, all, all in quiet mode)
docker container ls
docker container ls --all
docker container ls -a -q