docker与虚拟机相比,没有虚拟化内核,转而使用宿主机的内核。因此docker更轻更快
docker缺点:后端兼容性测试需求。把软件安装在不同的操作系统上进行测试,观察软件运行是否良好。
不能用docker做兼容性测试
uname -a 查看系统内核版本
docker关键技术:
- Namespace:通过名称控件达到了网络隔离
- 联合文件系统:通过联合文件系统达到了文件目录的隔离
- Cgroups:阻止容器中的软件和进程无限制的使用宿主机中的资源达到了资源隔离,如CPU和内存。
组织容器除了内核共享,其他的都不是共享的
docker测试应用:
- 搭建测试环境
- 搭建各类基础服务
- 搭建测试执行环境
选择docker的原因:
- docker相对虚拟机轻量级,更轻更快
- docker使用简单
- docker共享,有大量的镜像可以使用
查看docker命令
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/Users/chenshanju/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/Users/chenshanju/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/Users/chenshanju/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/Users/chenshanju/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
builder Manage builds
checkpoint Manage checkpoints
config Manage Docker configs
container Manage containers
engine Manage the docker engine
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
deploy Deploy a new stack or update an existing stack
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
查看docker信息
docker版本号:从17年开始,以年-月命名版本号
Containers: 3 #当前的容器
Running: 1 #运行中的容器
Paused: 0
Stopped: 2 #已停止的容器
Images: 13 #镜像数量
Server Version: 18.09.0-ce-beta1 #docker版本
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: 468a545b9edcd5932818eb9de8e72413e616e86e
runc version: 69663f0bd4b60df09991c08812a60108003fa340
init version: fec3683
Security Options:
seccomp
Profile: default
Kernel Version: 4.9.125-linuxkit
Operating System: Docker for Mac
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 3.855GiB
Name: linuxkit-025000000001
ID: IY7T:MW22:QBUX:KOJW:SOBV:TJUK:VXQA:HWGF:ZWXD:TAJP:KGPP:AKQ5
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): true
File Descriptors: 32
Goroutines: 57
System Time: 2018-11-02T08:12:50.1509806Z
EventsListeners: 2
HTTP Proxy: gateway.docker.internal:3128
HTTPS Proxy: gateway.docker.internal:3129
Registry: https://index.docker.io/v1/
Labels:
Experimental: true
Insecure Registries:
127.0.0.0/8
Registry Mirrors:
https://i2piuqyy.mirror.aliyuncs.com/
Live Restore Enabled: false
Product License: Community Engine
docker官方下载地址:https://hub.docker.com
注意:不用登陆,直接搜索镜像即可。一般选择官方镜像,如Jenkins,选择official
联合文件系统
如下载Jenkins时,有20层,Jenkins是一个经过20层文件修改生成的镜像
优点:节省硬盘空间
FAQ:
1.docker安装后,命令行使用docker,提示命令不可用,如下图所示
原因:/usr/local/bin未生效,将/usr/local/bin添加到环境变量即可export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
2.centOS安装docker,提示Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
解决方法:
systemctl daemon-reload
sudo service docker restart
sudo service docker status
#再次执行ps,不会再报错
docker ps
sudo service docker status