一. 在镜像中定义卷

1. Dockerfile中定义卷的案例

VOLUME /app/data
VOLUME /app/data, /app/profiles, /app/config
VOLUME ["/app/data", "/app/profiles", "/app/config"]

注解:

  • 第一行代表定义一个单 一的卷挂载在/app/data。
  • 第二行代表定义了三个卷,使用逗号进行分隔
  • 第三行代表定义了三个卷,只不过使用的是JSON数组

2. 获取数据卷信息案例1

(1)拉取名字叫做mongo:3.7的镜像

[root@c720120 ~]# docker image pull mongo:3.7
3.7: Pulling from library/mongo
b234f539f7a1: Pull complete
55172d420b43: Pull complete

(2)使用docker image inspect命令检查数据卷信息

[root@c720120 ~]# docker image inspect    --format='{{json .ContainerConfig.Volumes}}'     mongo:3.7
{"/data/configdb":{},"/data/db":{}}

(3)运行mongodb的实例

[root@c720120 ~]# docker run --name my-mongo -d mongo:3.7
0145aa8906d9e62823e091c3fbcfbce50bc27b27224f2cca456182d0dc52d9bc

(4)获取卷创建的详细信息

[root@c720120 ~]# docker inspect --format '{{json .Mounts}}' my-mongo
[{"Type":"volume","Name":"654e63e15e1366b10f661b5909bf5823e70637adf75252f4d7bdace5db3da357","Source":"/var/lib/docker/volumes/654e63e15e1366b10f661b5909bf5823e70637adf75252f4d7bdace5db3da357/_data","Destination":"/data/configdb","Driver":"local","Mode":"","RW":true,"Propagation":""},{"Type":"volume","Name":"083ed210294f7c7333d31f72123f5f2030caf0dfa56c5ba9375c590fbb9da99b","Source":"/var/lib/docker/volumes/083ed210294f7c7333d31f72123f5f2030caf0dfa56c5ba9375c590fbb9da99b/_data","Destination":"/data/db","Driver":"local","Mode":"","RW":true,"Propagation":""}]

二. 获得Docker系统的信息

1. 获得Docker基本信息

[root@c720120 ~]# docker version
Client:
  Version:      18.05.0-ce
  API version:  1.37
  Go version:   go1.9.5
  Git commit:   f150324
  Built:        Wed May  9 22:14:54 2018
  OS/Arch:      linux/amd64
  Experimental: false
  Orchestrator: swarm

Server:
  Engine:
   Version:      18.05.0-ce
   API version:  1.37 (minimum version 1.12)
   Go version:   go1.9.5
   Git commit:   f150324
   Built:        Wed May  9 22:18:36 2018
   OS/Arch:      linux/amd64
   Experimental: false

2. 获得Docker的系统相关信息

[root@c720120 ~]# docker system info
Containers: 22
  Running: 18
  Paused: 0
  Stopped: 4
Images: 55
Server Version: 18.05.0-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: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
  seccomp
   Profile: default
Kernel Version: 3.10.0-693.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 8
Total Memory: 7.641GiB
Name: c720120.xiodi.cn
ID: 3LFN:DY55:44IN:ZYQF:SCLG:LH7U:P2XQ:RLOP:WMMN:O7OA:C5Z5:KFC6
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: mike0405
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
  127.0.0.0/8
Registry Mirrors:
  https://av0eyibf.mirror.aliyuncs.com/
Live Restore Enabled: false

三. 检查Docker主机的资源消耗

1. 显示当前使用的资源和多少空间可能会被回收

[root@c720120 ~]# docker system df
TYPE                TOTAL               ACTIVE              SIZE                RECLAIMABLE
Images              34                  12                  3.32GB              2.159GB (65%)
Containers          22                  18                  10.66kB             126B (1%)
Local Volumes       6                   3                   362.1MB             47.24MB (13%)
Build Cache

2. 如果想要显示更中详细的信息,使用-v选项。

[root@c720120 ~]# docker system df -v
Images space usage:

REPOSITORY                                                             TAG                 IMAGE ID            CREATED ago         SIZE                SHARED SIZE         UNIQUE SiZE         CONTAINERS
mongo                                                                  3.7                 5651314706c2        3 hours ago ago     365.3MB             0B                  365.3MB             1
my-website                                                             1.0                 26a2c3c3133d        10 hours ago ago    18MB                18MB                99B                 1
<none>                                                                 <none>              51e46f702575        10 hours ago ago    18MB                18MB                73B                 0
hello-world                                                            latest              e6de691461d8        10 hours ago ago    177.8MB             4.148MB             173.6MB             0
my-centos                                                              latest              fcc50aa21ce3        11 hours ago ago    271.7MB             199.7MB             71.97MB             0
<none>                                                                 <none>              48746de3c746        11 hours ago ago    902.3MB             902.3MB             0B                  0
my-alpine                                                              latest              dd2e0b200d6d        12 hours ago ago    5.647MB             4.148MB             1.499MB             0
centos                                                                 7                   49f7960eb7e4        27 hours ago ago    199.7MB             199.7MB             0B                  0
quay.io/kubernetes-for-developers/nodejs                               0.2.0               593c8caeab0d        4 days ago ago      65.38MB             10.56MB             54.83MB             0
quay.io/kubernetes-for-developers/flask                                0.1.0               affcedaf18ef        4 days ago ago      64.97MB             10.56MB             54.41MB             0
busybox                                                                latest              8c811b4aec35        13 days ago ago     1.146MB             0B                  1.146MB             0
python                                                                 2.7                 5a7d0660d94a        4 weeks ago ago     902.3MB             902.3MB             0B                  0
nginx                                                                  alpine              ebe2c7c61055        8 weeks ago ago     18MB                18MB                0B                  0
k8s.gcr.io/kube-proxy-amd64                                            v1.10.0             bfc21aadc7d3        2 months ago ago    97.04MB             0B                  97.04MB             1
k8s.gcr.io/kube-scheduler-amd64                                        v1.10.0             704ba848e69a        2 months ago ago    50.39MB             1.146MB             49.25MB             1
k8s.gcr.io/kube-apiserver-amd64                                        v1.10.0             af20925d51a3        2 months ago ago    225MB               1.146MB             223.8MB             1
k8s.gcr.io/kube-controller-manager-amd64                               v1.10.0             ad86dbed1555        2 months ago ago    147.8MB             1.146MB             146.7MB             1
k8s.gcr.io/etcd-amd64                                                  3.1.12              52920ad46f5b        2 months ago ago    193.2MB             1.146MB             192.1MB             0
fundamentalsofdocker/ch08-web                                          1.0                 922e085ed002        3 months ago ago    72.01MB             3.966MB             68.04MB             0
fundamentalsofdocker/ch08-db                                           1.0                 4953d5353c17        3 months ago ago    39.46MB             4.148MB             35.31MB             0
coredns/coredns                                                        1.0.6               d4b7466213fe        3 months ago ago    39.88MB             0B                  39.88MB             2
k8s.gcr.io/kubernetes-dashboard-amd64                                  v1.8.3              0c60bcf89900        3 months ago ago    102.3MB             0B                  102.3MB             2
registry.cn-shenzhen.aliyuncs.com/rancher_cn/heapster-amd64            v1.5.1              c41e77c31c91        3 months ago ago    75.32MB             0B                  75.32MB             0
<none>                                                                 <none>              65f32704f7a3        4 months ago ago    10.12MB             3.966MB             6.149MB             0
quay.io/coreos/flannel                                                 v0.10.0-amd64       f0fad859c909        4 months ago ago    44.6MB              4.148MB             40.45MB             2
registry.cn-hangzhou.aliyuncs.com/k8sth/heapster-grafana-amd64         v4.4.3              edd7018a59de        4 months ago ago    151.5MB             1.129MB             150.4MB             0
alpine                                                                 3.7                 3fd9065eaf02        4 months ago ago    4.148MB             4.148MB             0B                  1
k8s.gcr.io/k8s-dns-dnsmasq-nanny-amd64                                 1.14.8              c2ce1ffb51ed        5 months ago ago    40.95MB             0B                  40.95MB             0
k8s.gcr.io/k8s-dns-sidecar-amd64                                       1.14.8              6f7f2dc7fab5        5 months ago ago    42.21MB             4.144MB             38.07MB             0
k8s.gcr.io/k8s-dns-kube-dns-amd64                                      1.14.8              80cc5ea4b547        5 months ago ago    50.46MB             4.144MB             46.31MB             0
k8s.gcr.io/pause-amd64                                                 3.1                 da86e6ba6ca1        5 months ago ago    742.5kB             0B                  742.5kB             0
ubuntu                                                                 17.04               fe1cc5b91830        5 months ago ago    95.63MB             0B                  95.63MB             1
registry.cn-shenzhen.aliyuncs.com/rancher_cn/heapster-influxdb-amd64   v1.3.3              577260d221db        9 months ago ago    12.55MB             1.129MB             11.42MB             0
registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64                    3.0                 99e59f495ffa        2 years ago ago     746.9kB             0B                  746.9kB             8

Containers space usage:

CONTAINER ID        IMAGE                                                     COMMAND                  LOCAL VOLUMES       SIZE                CREATED ago         STATUS                    NAMES
0145aa8906d9        mongo:3.7                                                 "docker-entrypoint.s…"   2                   0B                  8 minutes ago ago   Up 8 minutes              my-mongo
557b896ff138        my-website:1.0                                            "nginx -g 'daemon of…"   0                   2B                  10 hours ago ago    Up 10 hours               my-site
f29815cfea52        ubuntu:17.04                                              "/bin/bash"              1                   73B                 10 hours ago ago    Exited (1) 10 hours ago   reader
02f3d25fe440        alpine                                                    "/bin/sh"                1                   53B                 10 hours ago ago    Exited (0) 10 hours ago   writer
eddd516d5c67        0c60bcf89900                                              "/dashboard --insecu…"   0                   0B                  10 hours ago ago    Up 10 hours               k8s_kubernetes-dashboard_kubernetes-dashboard-7b44ff9b77-87vnz_kube-system_f4b7d3c3-6354-11e8-aec8-525400da66d3_2
f628fc5261cb        0c60bcf89900                                              "/dashboard --insecu…"   0                   0B                  10 hours ago ago    Exited (1) 10 hours ago   k8s_kubernetes-dashboard_kubernetes-dashboard-7b44ff9b77-87vnz_kube-system_f4b7d3c3-6354-11e8-aec8-525400da66d3_1
4497d8983aa8        f0fad859c909                                              "/opt/bin/flanneld -…"   0                   0B                  10 hours ago ago    Up 10 hours               k8s_kube-flannel_kube-flannel-ds-jpn69_kube-system_d511775a-6350-11e8-aec8-525400da66d3_0
150eb223d319        d4b7466213fe                                              "/coredns -conf /etc…"   0                   5.27kB              10 hours ago ago    Up 10 hours               k8s_coredns_coredns-7997f8864c-bqjl6_kube-system_06d0a127-634e-11e8-8a76-525400da66d3_0
ce50540a5da6        d4b7466213fe                                              "/coredns -conf /etc…"   0                   5.27kB              10 hours ago ago    Up 10 hours               k8s_coredns_coredns-7997f8864c-7flkx_kube-system_06cd6faf-634e-11e8-8a76-525400da66d3_0
20ec466d4e7d        ad86dbed1555                                              "kube-controller-man…"   0                   0B                  10 hours ago ago    Up 10 hours               k8s_kube-controller-manager_kube-controller-manager-c720120.xiodi.cn_kube-system_9ebd85f31a07b860847b300d2124c485_0
ccc1fa2f461b        bfc21aadc7d3                                              "/usr/local/bin/kube…"   0                   0B                  10 hours ago ago    Up 10 hours               k8s_kube-proxy_kube-proxy-8g8xs_kube-system_06d4d12f-634e-11e8-8a76-525400da66d3_0
1e8615e3be7d        f0fad859c909                                              "cp -f /etc/kube-fla…"   0                   0B                  10 hours ago ago    Exited (0) 10 hours ago   k8s_install-cni_kube-flannel-ds-jpn69_kube-system_d511775a-6350-11e8-aec8-525400da66d3_0
818acc639132        af20925d51a3                                              "kube-apiserver --re…"   0                   0B                  10 hours ago ago    Up 10 hours               k8s_kube-apiserver_kube-apiserver-c720120.xiodi.cn_kube-system_dc5a90c76fa85961f74db59b5ef2e0c1_0
68f022ef851b        704ba848e69a                                              "kube-scheduler --ku…"   0                   0B                  10 hours ago ago    Up 10 hours               k8s_kube-scheduler_kube-scheduler-c720120.xiodi.cn_kube-system_ca4d1ecae9f198efae15156d524bb1d0_0
5184cfdeab1d        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_kube-flannel-ds-jpn69_kube-system_d511775a-6350-11e8-aec8-525400da66d3_0
f5b09907ac58        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_kube-controller-manager-c720120.xiodi.cn_kube-system_9ebd85f31a07b860847b300d2124c485_0
94637d8b8614        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_kube-proxy-8g8xs_kube-system_06d4d12f-634e-11e8-8a76-525400da66d3_0
f8965fe90c07        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_coredns-7997f8864c-bqjl6_kube-system_06d0a127-634e-11e8-8a76-525400da66d3_0
09ac5692e5ac        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_kube-apiserver-c720120.xiodi.cn_kube-system_dc5a90c76fa85961f74db59b5ef2e0c1_0
c788ac0d3604        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_kube-scheduler-c720120.xiodi.cn_kube-system_ca4d1ecae9f198efae15156d524bb1d0_0
d0ee0f4e50bb        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_kubernetes-dashboard-7b44ff9b77-87vnz_kube-system_f4b7d3c3-6354-11e8-aec8-525400da66d3_0
b8b969bf904a        registry.cn-hangzhou.aliyuncs.com/k8sth/pause-amd64:3.0   "/pause"                 0                   0B                  10 hours ago ago    Up 10 hours               k8s_POD_coredns-7997f8864c-7flkx_kube-system_06cd6faf-634e-11e8-8a76-525400da66d3_0

Local Volumes space usage:

VOLUME NAME                                                        LINKS               SIZE
docker_pets-data                                                   0                   47.24MB
my-data                                                            0                   57B
share-data                                                         2                   20B
shared-data                                                        0                   0B
654e63e15e1366b10f661b5909bf5823e70637adf75252f4d7bdace5db3da357   1                   0B
083ed210294f7c7333d31f72123f5f2030caf0dfa56c5ba9375c590fbb9da99b   1                   314.8MB

四. 修剪未使用的资源

1. 修剪未使用的容器

(1)修剪容器(没有在运行状态的容器)

[root@c720120 ~]# docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
f29815cfea52eae2dd2e37a43d5260f5265299852f8f216ca7437b76222739c2
02f3d25fe440b709840abb055bff25ad9a90ce12acdcd2734249e5a8faff6b2d
f628fc5261cb26d15ff7d24b02abc992392c54a736f0333d9cee16cc324e24da
1e8615e3be7d24f41060319cb762a3e66b7470ab74c5af87285d6c0003f1b99e

Total reclaimed space: 126B

(2)如果在修剪时不想再次确认,可以使用-f或者—force选项。

[root@c720120 ~]# docker container prune –f

(3)如果想要移除所有的容器(包括那些在运行的),prune命令无法做到,使用以下命令.

[root@c720120 ~]# docker container rm -f $(docker container ls -aq)

2. 修剪镜像

(1)修剪镜像(没有在使用的镜像)

[root@c720120 ~]# docker image prune

(2)修剪镜像,如果不想再三确认,请使用-f或者—force选项。

[root@c720120 ~]# docker image prune –f

(3)移除所有的镜像,不仅是那些孤立的镜像

[root@c720120 ~]# docker image prune –-force –all

3. 修剪卷

(1)修剪卷(没有在使用的卷)

[root@c720120 ~]# docker volume prune

(2)修剪过滤器过滤的指定的卷

[root@c720120 ~]# docker volume prune –filter ‘label=demo’

也可以使用多个过滤器过滤卷

[root@c720120 ~]# docker volume prune –filter ‘label=demo’ –filter ‘label=test’

4. 修剪网络

[root@c720120 ~]# docker network prune

5. 执行一条命令,修剪所有的东西,包括卷,网络,容器,镜像。

[root@c720120 ~]# docker system prune

五. Docker系统事件

当docker引擎在创建,运行,停止 和移除容器和其它资源时,比如卷和网络,均会产生事件日志。

案例1:

(1)开启系统事件

[root@c720120 ~]# docker system events

(2)在Docker host的另一个终端上执行创建容器命令。

[root@c720120 ~]# docker container run --rm alpine echo "Hello World"
Hello World

(3)查看输出的事件信息

[root@c720120 ~]# docker system events
2018-06-06T09:51:45.412499798+08:00 container create 26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef (image=alpine, name=gifted_bassi)
2018-06-06T09:51:45.417325987+08:00 container attach 26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef (image=alpine, name=gifted_bassi)
2018-06-06T09:51:45.536770127+08:00 network connect 8d4ce133354ba6e3ab01684cf18b88535230647e78a6d698f1ef8d79f767b169 (container=26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef, name=bridge, type=bridge)
2018-06-06T09:51:46.087623064+08:00 container start 26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef (image=alpine, name=gifted_bassi)
2018-06-06T09:51:46.218351340+08:00 container die 26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef (exitCode=0, image=alpine, name=gifted_bassi)
2018-06-06T09:51:46.376077683+08:00 network disconnect 8d4ce133354ba6e3ab01684cf18b88535230647e78a6d698f1ef8d79f767b169 (container=26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef, name=bridge, type=bridge)
2018-06-06T09:51:46.467148084+08:00 container destroy 26f1bc504b5d19735558085005225a6d7ecb7bebd4c4f060c1a20c565a130cef (image=alpine, name=gifted_bassi)

(4)让输出事件信息按指定的格式进行输出

[root@c720120 ~]#  docker system events --format 'Type={{.Type}} Image={{.Actor.Attributes.image}} Action={{.Action}}'

(5)输出信息如下

[root@c720120 ~]#  docker system events --format 'Type={{.Type}} Image={{.Actor.Attributes.image}} Action={{.Action}}'
Type=container Image=alpine Action=create
Type=container Image=alpine Action=attach
Type=network Image=<no value> Action=connect
Type=container Image=alpine Action=start
Type=container Image=alpine Action=die
Type=network Image=<no value> Action=disconnect
Type=container Image=alpine Action=destroy

Docker数据卷和Docker系统管理(二)的更多相关文章

  1. Docker数据卷和Docker系统管理(一)

    一. 创建和挂载数据卷 1. 创建数据卷 (1)执行下列命令,创建一个名为my-data的数据卷 [root@c720120 ~]# docker volume create my-data my-d ...

  2. docker 数据卷和docker数据卷容器以及数据卷的备份和还原

    一:数据卷 1.什么是数据卷 数据卷是通过特殊设计的目录,可以绕过联合文件系统,为一个或者多个容器提供服务,数据卷是在docker宿主机当中,数据卷可以是文件也可以是文件夹. 2.特点 1.数据卷在容 ...

  3. docker数据卷学习-利用数据卷实现mysql的快速恢复和迁移

    docker数据卷学习 一 新建带有数据卷的容器 1.从docker hub下载centos7镜像 # docker pull centos 2. 创建container # docker run - ...

  4. Docker学习第三天(Docker数据卷管理)

    1.Docker数据卷管理 在Docker中,要想实现数据的持久化(所谓Docker的数据持久化即数据不随着Container的结束而结束),需要将数据从宿主机挂载到容器中.目前Docker提供了三种 ...

  5. docker 数据卷之进阶篇

    笔者在<Docker 基础 : 数据管理>一文中介绍了 docker 数据卷(volume) 的基本用法.随着使用的深入,笔者对 docker 数据卷的理解与认识也在不断的增强.本文将在前 ...

  6. 1.docker 数据卷的备份和恢复(非大数据量)

    在生产环境中使用 Docker,很多时候需要对数据进行持久化,或者进行容器间的数据共享. 容器中的管理数据主要有两种方式: 数据卷 (Data Volumes): 容器内数据直接映射到本地主机环境: ...

  7. 聊聊Docker数据卷和数据卷容器

    当程序在容器运行的时候,特别是需要与其他容器中的程序或容器外部程序进行沟通交流,这时需要进行数据交换,作为常用的两种沟通数据的方式,网络通信与文件读写是需要提供给程序的支持, [数据卷] 文件是数据持 ...

  8. docker 数据卷 ---- 进阶篇

    笔者在<Docker 基础 : 数据管理>一文中介绍了 docker 数据卷(volume) 的基本用法.随着使用的深入,笔者对 docker 数据卷的理解与认识也在不断的增强.本文将在前 ...

  9. 实例解析Docker数据卷+数据卷容器+flocker数据共享+DockerHub操作

    Docker内部数据管理和Docker之间的数据共享为数据卷和数据卷容器,实例解析1.将本地的文件作为容器的数据卷,2.数据卷flocker插件实现容器集群(或者Docker Swarm)的数据共享3 ...

随机推荐

  1. Ambari和ClouderaManager主要不同对比

    打算对新建的hadoop集群使用管理工具,列了以下主要的不同点: 主要的不同点 apache Ambari ClouderaManager Express(免费版) 配置版本控制和历史记录 支持 不支 ...

  2. Centos7中使用ipset

      1.禁用firewalld systemctl stop firewalld systemctl disable firewalld   2.安装ipset yum -y install ipse ...

  3. MSBuild问题积累

    我想要当属性ConfigurationType定义为StaticLibrary时,将其重新定义为StaticLibrary,按照以下来做,实现不了. <ConfigurationType> ...

  4. 还不会做! 树上的gcd 树分治 UOJ33

    题目链接:http://uoj.ac/problem/33 题解链接:http://vfleaking.blog.uoj.ac/blog/38 现在感觉到了做OI的层层递进的思路的伟大之处,作为一个大 ...

  5. 2015/9/22 Python基础(18):组合、派生和继承

    一个类被定义后,目标就是把它当成一个模块来使用,并把这些对象嵌入到你的代码中去,同其他数据类型及逻辑执行流混合使用.有两种方法可以在你的代码中利用类.第一种是组合,就是让不同的类混合并加入到其他类中, ...

  6. 【BZOJ】2565: 最长双回文串

    [题意]给定小写字母字符串s,求最长的 [ 可以分成左右两个回文串的 ] 子串,n<=10^5. [算法]回文树 [题解]对于每个字符x,处理出以x结尾的最长回文串,以x开头的最长回文串,然后枚 ...

  7. 【洛谷 P4016】 负载平衡问题(费用流)

    题目链接 环形均分纸牌,既然是网络流23题的那就用网络流做把. 套路拆点. 供需平衡. 源点向大于平均数的点的入点连流量为这个数减去平均数的差,费用为0的边,表示需要移走这么多. 小于平均数的点的出点 ...

  8. NYOJ 35 表达式求值 (字符串处理)

    题目链接 描述 ACM队的mdd想做一个计算器,但是,他要做的不仅仅是一计算一个A+B的计算器,他想实现随便输入一个表达式都能求出它的值的计算器,现在请你帮助他来实现这个计算器吧. 比如输入:&quo ...

  9. Go语言 8 反射

    文章由作者马志国在博客园的原创,若转载请于明显处标记出处:http://www.cnblogs.com/mazg/ Go学习群:415660935 8.1概念和作用 Reflection(反射)在计算 ...

  10. Coursera在线学习---第六节.构建机器学习系统

    备: High bias(高偏差) 模型会欠拟合    High variance(高方差) 模型会过拟合 正则化参数λ过大造成高偏差,λ过小造成高方差 一.利用训练好的模型做数据预测时,如果效果不好 ...