Docker基础 - 02安装
一、安装简介
1.1 依赖的基础环境
- 64bits CPU
- Linux Kernel 3.10+
- Linux Kernel cgroups and namespaces
1.2 CentOS 7
- "Extras" repository
1.3 Docker Daemon
- systemctl start docker.service
1.4 Docker Client
- docker [OPTIONS] COMMAND [arg...]
二、安装步骤
2.1 系统初始化: 设置主机名、关闭SELinux、关闭防火墙等
2.2 删除原有包、更新yum、安装基础环境
[root@localhost ~]# yum remove docker docker-client docker-client-latest docker-common docker-latest \
docker-latest-logrotate docker-logrotate docker-engine [root@localhost ~]# yum -y update [root@localhost ~]# yum -y install yum-utils device-mapper-persistent-data lvm2
2.3 更新yum源仓库文件
[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo 已加载插件:fastestmirror adding repo from: https://download.docker.com/linux/centos/docker-ce.repo grabbing file https://download.docker.com/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo repo saved to /etc/yum.repos.d/docker-ce.repo [root@localhost ~]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo [root@localhost ~]# yum clean all [root@localhost ~]# yum repolist
2.4 安装Docker
[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
[root@localhost ~]# docker --version
Docker version 19.03.13, build 4484c46d9d
2.5 配置Docker配置文件
设置Docker镜像加速: 阿里云账户
[root@localhost ~]# vi /etc/docker/daemon.json [root@localhost ~]# cat /etc/docker/daemon.json { "registry-mirrors": ["https://b5imc2v6.mirror.aliyuncs.com"], "log-driver": "json-file", "log-opts": { "max-size": "100m" } } [root@localhost ~]# systemctl daemon-reload
{ "registry-mirrors": ["https://b5imc2v6.mirror.aliyuncs.com"], "exec-opts": ["native.cgroupdriver=systemd"], "log-driver": "json-file", "log-opts": { "max-size": "100m" }, "storage-driver": "overlay2", "storage-opts": [ "overlay2.override_kernel_check=true" ], "bip": "10.0.1.1/24" }
2.6 启动Docker服务
[root@localhost ~]# systemctl enable --now docker Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service. [root@localhost ~]# systemctl start docker.service
2.7 远程管理Docker服务
dockerd守护进程的C/S模式,其默认仅监听Unix Socket格式的地址,/var/run/docker.sock;
如果使用TCP套接字,需在/etc/docker/daemon.json添加
"hosts": ["tcp://192.168.234.6:39001","unix:///var/run/docker.sock"]
[root@cl-server ~]# cat /etc/docker/daemon.json "hosts": ["tcp://192.168.234.6:39001","unix:///var/run/docker.sock"] [root@cl-server ~]# vi /usr/lib/systemd/system/docker.service #ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock ExecStart=/usr/bin/dockerd [root@cl-server ~]# systemctl daemon-reload [root@cl-server ~]# systemctl start docker [root@cl-node01 ~]# docker -H 192.168.234.6:39001 ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [root@cl-node01 ~]# docker -H 192.168.234.6:39001 images REPOSITORY TAG IMAGE ID CREATED SIZE kunking/httpd v0.1-3 5a38ea0db06f 3 hours ago 1.23MB kunking/httpd v0.1-2 3d7b42c71d01 25 hours ago 1.23MB registry.cn-hangzhou.aliyuncs.com/kunking/httpd v0.1-2 3d7b42c71d01 25 hours ago 1.23MB kunking/httpd v0.1-1 b680392e10f2 25 hours ago 1.23MB busybox latest 388056c9a683 2 weeks ago 1.23MB
三、Docker 信息
3.1 查看Docker 版本
[root@component ~]# docker version
Client: Docker Engine - Community
Version: 20.10.10
API version: 1.41
Go version: go1.16.9
Git commit: b485636
Built: Mon Oct 25 07:44:50 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.10
API version: 1.41 (minimum version 1.12)
Go version: go1.16.9
Git commit: e2f740d
Built: Mon Oct 25 07:43:13 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.11
GitCommit: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc:
Version: 1.0.2
GitCommit: v1.0.2-0-g52b36a2
docker-init:
Version: 0.19.0
GitCommit: de40ad0
3.2 Docker Info信息
[root@component ~]# docker info
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
scan: Docker Scan (Docker Inc., v0.9.0)
Server:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 20.10.10
Storage Driver: overlay2
Backing Filesystem: xfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
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 io.containerd.runc.v2 io.containerd.runtime.v1.linux
Default Runtime: runc
Init Binary: docker-init
containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8
runc version: v1.0.2-0-g52b36a2
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 3.10.0-957.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 1.786GiB
Name: component
ID: UQUS:KTDY:NNLY:DPWU:AKP7:CBE3:OFPY:W7SO:NLM5:AD5S:TR5W:GTVD
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
Registry Mirrors:
https://b5imc2v6.mirror.aliyuncs.com/
Live Restore Enabled: false
3.3 Docker命令
[root@component ~]# docker -h
Flag shorthand -h has been deprecated, please use --help
Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-c, --context string Name of the context to use to connect to the daemon (overrides DOCKER_HOST env var and default context set with "docker context use")
-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 "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
app* Docker App (Docker Inc., v0.9.1-beta3)
builder Manage builds
buildx* Build with BuildKit (Docker Inc., v0.6.3-docker)
config Manage Docker configs
container Manage containers
context Manage contexts
image Manage images
manifest Manage Docker image manifests and manifest lists
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
scan* Docker Scan (Docker Inc., v0.9.0)
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
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.
To get more help with docker, check out our guides at https://docs.docker.com/go/guides/
[root@component ~]#