Docker 基础命令介绍

简介:

Docker是一种C/S结构,所以就会有客户端和服务端。Docker支持很多子命令,例如我们在命令行docker然后tab键会出来很多命令

当然docker工具很多,除了 docker 命令行工具,用户也可以通过 REST API 与服务器通信

Docker daemon是服务器组件,以 Linux 后台服务的方式运行。可以通过命令:systemctl status docker.service看到

Docker daemon 运行在 Docker host 上,负责创建、运行、监控容器,构建、存储镜像。

监听地址的配置:

默认docker daemon只能监听本地host,如果远程要访问,需要打开tcp监听,如下:

1
/etc/systemd/system/multi-user .target.wants /docker .service
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
[Unit]
Description=Docker Application Container Engine
Documentation=https: //docs .docker.com
After=network.target docker.socket firewalld.service
Requires=docker.socket
 
[Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart= /usr/bin/dockerd  -H fd: //
 
#上面这里如果改成这样就开启了监听远程所有端口:ExecStart=/usr/bin/dockerd -H fd:// -H tcp://0.0.0.0
 
ExecReload= /bin/kill  -s HUP $MAINPID
LimitNOFILE=1048576
# Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNPROC=infinity
LimitCORE=infinity
# Uncomment TasksMax if your systemd version supports it.
# Only systemd 226 and above support this version.
TasksMax=infinity
TimeoutStartSec=0
# set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate= yes
# kill only the docker process, not all processes in the cgroup
KillMode=process
 
[Install]
WantedBy=multi-user.target

重启服务端docker

1
2
systemctl daemon-reload 
systemctl restart docker.service

调试

可以通过在客户端通过H参数来指定服务器和info子命令来查看服务端信息

这里可以看到哦啊服务端运行情况

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
root@d1: /etc/apt # docker -H 192.168.56.132 info
Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
Images: 1
Server Version: 17.03.1-ce
Storage Driver: aufs
  Root Dir:  /var/lib/docker/aufs
  Backing Filesystem: extfs
  Dirs: 9
  Dirperm1 Supported:  true
Logging Driver: json- file
Cgroup Driver: cgroupfs
Plugins: 
  Volume:  local
  Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 4ab9917febca54791c5f071a9d1f404867857fcc
runc version: 54296cf40ad8143b62dbcaa1d90e520a2136ddfe
init version: 949e6fa
Security Options:
  apparmor
  seccomp
   Profile: default
Kernel Version: 4.4.0-31-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.842 GiB
Name: d1
ID: SQ7Y:TBJA:LS5G:IQNB:CIHC:6T2D:J22X:F3QK:7AS2:7KLN:NIIQ:JLXY
Docker Root Dir:  /var/lib/docker
Debug Mode (client):  false
Debug Mode (server):  false
Registry: https: //index .docker.io /v1/
WARNING: No swap limit support
Experimental:  false
Insecure Registries:
  127.0.0.0 /8
Registry Mirrors:
  http: //febb9aec .m.daocloud.io
Live Restore Enabled:  false




本文转自 kesungang 51CTO博客,原文链接:http://blog.51cto.com/sgk2011/1923361,如需转载请自行联系原作者
相关文章
|
1月前
|
前端开发 关系型数据库 MySQL
IDEA集成Docker插件打包服务镜像与运行【附Docker命令汇总】
IDEA集成Docker插件打包服务镜像与运行【附Docker命令汇总】
|
1天前
|
监控 Docker 容器
Docker从入门到精通:Docker log 命令学习
了解 Docker 日志管理对容器监控至关重要。`docker logs` 命令用于查看和管理容器日志,例如,`docker logs <container_name>` 显示容器日志,`-f` 或 `--follow` 实时跟踪日志,`--tail` 显示指定行数,`--timestamps` 添加时间戳,`--since` 按日期筛选。Docker 支持多种日志驱动,如 `syslog`,可通过 `--log-driver` 配置。有效管理日志能提升应用程序的稳定性和可维护性。
3 0
|
15天前
|
应用服务中间件 Docker 容器
docker 镜像常用命令
docker 镜像常用命令
35 0
|
15天前
|
Linux Docker 容器
docker 容器常用命令
docker 容器常用命令
13 0
|
23天前
|
JSON 缓存 程序员
Docker常用命令以及生命周期管理
Docker常用命令以及生命周期管理
45 2
|
26天前
|
开发工具 Docker 索引
Docker解决没有vi、vim等命令
Docker解决没有vi、vim等命令
50 0
|
30天前
|
监控 数据可视化 虚拟化
Docker容器常用命令笔记分享
Docker容器常用命令笔记分享
50 2
|
1月前
|
NoSQL 应用服务中间件 nginx
Docker命令实战
Docker命令实战
61 1
|
1月前
|
关系型数据库 MySQL 数据库
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
40 0
|
1月前
|
Unix Docker 容器
【超强图解Docker常见命令与实战】
【超强图解Docker常见命令与实战】
51 0