云原生基礎(chǔ) docker & harbor

Linux Namespace淺析

https://zhuanlan.zhihu.com/p/102364063

Namespace是將內(nèi)核的全局資源做封裝爆班,使得每個(gè)Namespace都有一份獨(dú)立的資源柿菩,因此不同的進(jìn)程在各自的Namespace內(nèi)對(duì)同一種資源的使用不會(huì)互相干擾。

Linux對(duì)Namespace的操作懦胞,主要是通過clone凉泄、setns和unshare這3個(gè)系統(tǒng)調(diào)用來完成的后众,clone創(chuàng)建新進(jìn)程時(shí),接收一個(gè)叫flags的參數(shù)教藻,這些flag包括CLONE_NEWNS括堤、CLONE_NEWIPC、CLONE_NEWUTS哮肚、CLONE_NEWNET(Mount namespace)广匙、CLONE_NEWPIDCLONE_NEWUSER鸦致,用于創(chuàng)建新的namespace,這樣clone創(chuàng)建出來新進(jìn)程之后就屬于新的namespace了抗碰,后續(xù)新進(jìn)程創(chuàng)建的進(jìn)程默認(rèn)屬于同一namespace绽乔。

如果想要給已存在進(jìn)程設(shè)置新的namespace折砸,可通過unshare函數(shù)(long unshare(unsigned long flags))完成設(shè)置睦授,其入?yún)lags表示新的namespace。當(dāng)想要給已存在進(jìn)程設(shè)置已存在的namespace怖辆,可通過setns函數(shù)(int setns(int fd, int nstype))來完成設(shè)置删顶,每個(gè)進(jìn)程在procfs目錄下存儲(chǔ)其相關(guān)的namespace信息,可找到已存在的namesapce特咆,然后通過setns設(shè)置即可:

[root@centos ~]# ls -l /proc/10401/ns
總用量 0
lrwxrwxrwx 1 root root 0 1月  12 11:36 ipc -> ipc:[4026531839]
lrwxrwxrwx 1 root root 0 1月  12 11:36 mnt -> mnt:[4026531840]
lrwxrwxrwx 1 root root 0 1月  12 11:36 net -> net:[4026531956]
lrwxrwxrwx 1 root root 0 1月  12 11:36 pid -> pid:[4026531836]
lrwxrwxrwx 1 root root 0 1月  12 11:36 user -> user:[4026531837]
lrwxrwxrwx 1 root root 0 1月  12 11:36 uts -> uts:[4026531838]

上述每個(gè)虛擬文件對(duì)應(yīng)該進(jìn)程所處的namespace坚弱,如果其他進(jìn)程想進(jìn)入該namespace,open該虛擬文件獲取到fd碾阁,然后傳給setns函數(shù)的fd入?yún)⒓纯芍祝⒁馓摂M文件type和nstype要對(duì)應(yīng)上愁茁。

目前Linux內(nèi)核總共支持以下6種Namespace鹅很,分別是IPC罪帖、Network、Mount整袁、PID菠齿、UTS、User

  • IPC:隔離System V IPC和POSIX消息隊(duì)列坐昙。
  • Network:隔離網(wǎng)絡(luò)資源绳匀。
  • Mount:隔離文件系統(tǒng)掛載點(diǎn)。
  • PID:隔離進(jìn)程ID炸客。
  • UTS:隔離主機(jī)名和域名疾棵。
  • User:隔離用戶ID和組ID妇汗。

IPC

IPC也就是進(jìn)程間通信,Linux下有多種進(jìn)程間通信荆几,比如socket蝶溶、共享內(nèi)存嗜历、Posix消息隊(duì)列和SystemV IPC等,這里的IPC namespace針對(duì)的是SystemV IPC和Posix消息隊(duì)列抖所,其會(huì)用標(biāo)識(shí)符表示不同的消息隊(duì)列梨州,進(jìn)程間通過找到標(biāo)識(shí)符對(duì)應(yīng)的消息隊(duì)列來完成通信,IPC namespace做的事情就是相同的標(biāo)識(shí)符在不同namespace上對(duì)應(yīng)不同的消息隊(duì)列田轧,這樣不同namespace的進(jìn)程無法完成進(jìn)程間通信暴匠。

Network

Network Namespace隔離網(wǎng)絡(luò)資源,每個(gè)Network Namespace都有自己的網(wǎng)絡(luò)設(shè)備傻粘、IP地址每窖、路由表、/proc/net目錄弦悉、端口號(hào)等窒典。每個(gè)Network Namespace會(huì)有一個(gè)loopback設(shè)備(除此之外不會(huì)有任何其他網(wǎng)絡(luò)設(shè)備)。因此用戶需要在這里面做自己的網(wǎng)絡(luò)配置稽莉。IP工具已經(jīng)支持Network Namespace瀑志,可以通過它來為新的Network Namespace配置網(wǎng)絡(luò)功能。

Mount

Mount namesapce用戶隔離文件系統(tǒng)掛載點(diǎn),每個(gè)進(jìn)程能看到的文件系統(tǒng)都記錄在/proc/$$/mounts里劈猪。在創(chuàng)建了一個(gè)新的Mount Namespace后昧甘,進(jìn)程系統(tǒng)對(duì)文件系統(tǒng)掛載/卸載的動(dòng)作就不會(huì)影響到其他Namespace。

PID

PID Namespace用于隔離進(jìn)程PID號(hào)战得,這樣一來充边,不同的Namespace里的進(jìn)程PID號(hào)就可以是一樣的了。當(dāng)創(chuàng)建一個(gè)PID Namespace時(shí)常侦,第一個(gè)進(jìn)程的PID號(hào)是1痛黎,也就是init進(jìn)程。init進(jìn)程有一些特殊之處刮吧,例如init進(jìn)程需要負(fù)責(zé)回收所有孤兒進(jìn)程的資源湖饱。另外,發(fā)送給init進(jìn)程的任何信號(hào)都會(huì)被屏蔽杀捻,即使發(fā)送的是SIGKILL信號(hào)井厌,也就是說,在容器內(nèi)無法“殺死”init進(jìn)程致讥。

UTS

UTS為Unix Timesharing System的簡(jiǎn)稱仅仆,包含內(nèi)存名稱、版本垢袱、底層體系結(jié)構(gòu)等信息墓拜,UTS Namespace用于對(duì)主機(jī)名和域名進(jìn)行隔離,也就是uname系統(tǒng)調(diào)用使用的結(jié)構(gòu)體structutsname里的nodename和domainname這兩個(gè)字段请契,UTS這個(gè)名字也是由此而來的咳榜。為什么需要uts namespace呢,因?yàn)闉橹鳈C(jī)名可以用來代替IP地址爽锥,比如局域網(wǎng)通過主機(jī)名訪問機(jī)器涌韩。

User

User Namespace用來隔離用戶資源,比如一個(gè)進(jìn)程在Namespace里的用戶和組ID與它在host里的ID可以不一樣氯夷,這樣可以做到臣樱,一個(gè)host的普通用戶可以在該容器(user namespace)下?lián)碛衦oot權(quán)限,但是它的特權(quán)被限定在容器內(nèi)腮考。(容器內(nèi)的這類root用戶雇毫,實(shí)際上還是有很多特權(quán)操作不能執(zhí)行,基本上如果這個(gè)特權(quán)操作會(huì)影響到其他容器或者h(yuǎn)ost踩蔚,就不會(huì)被允許)

Linux Cgroup淺析

https://zhuanlan.zhihu.com/p/102372680

cgroups是Linux下控制一個(gè)(或一組)進(jìn)程的資源限制機(jī)制棚放,全稱是control groups,可以對(duì)cpu寂纪、內(nèi)存等資源做精細(xì)化控制席吴,比如目前很多的Docker在Linux下就是基于cgroups提供的資源限制機(jī)制來實(shí)現(xiàn)資源控制的;除此之外捞蛋,開發(fā)者也可以指直接基于cgroups來進(jìn)行進(jìn)程資源控制孝冒,比如8核的機(jī)器上部署了一個(gè)web服務(wù)和一個(gè)計(jì)算服務(wù),可以讓web服務(wù)僅可使用其中6個(gè)核拟杉,把剩下的兩個(gè)核留給計(jì)算服務(wù)庄涡。cgroups cpu限制除了可以限制使用多少/哪幾個(gè)核心之外,還可以設(shè)置cpu占用比(注意占用比是各自都跑滿情況下的使用比例搬设,如果一個(gè)cgroup空閑而另一個(gè)繁忙穴店,那么繁忙的cgroup是有可能占滿整個(gè)cpu核心的)。

cgroups概念

從實(shí)現(xiàn)角度來看拿穴,cgroups實(shí)現(xiàn)了一個(gè)通用的進(jìn)程分組框架泣洞,不同資源的具體管理工作由各cgroup子系統(tǒng)來實(shí)現(xiàn),當(dāng)需要多個(gè)限制策略比如同時(shí)針對(duì)cpu和內(nèi)存進(jìn)行限制默色,則同時(shí)關(guān)聯(lián)多個(gè)cgroup子系統(tǒng)即可球凰。

cgroups子系統(tǒng)

cgroups為每種資源定義了一個(gè)子系統(tǒng),典型的子系統(tǒng)如下:

  • cpu 子系統(tǒng)腿宰,主要限制進(jìn)程的 cpu 使用率呕诉。
  • cpuacct 子系統(tǒng),可以統(tǒng)計(jì) cgroups 中的進(jìn)程的 cpu 使用報(bào)告吃度。
  • cpuset 子系統(tǒng)甩挫,可以為 cgroups 中的進(jìn)程分配單獨(dú)的 cpu 節(jié)點(diǎn)或者內(nèi)存節(jié)點(diǎn)。
  • memory 子系統(tǒng)椿每,可以限制進(jìn)程的 memory 使用量伊者。
  • blkio 子系統(tǒng),可以限制進(jìn)程的塊設(shè)備 io间护。
  • devices 子系統(tǒng)删壮,可以控制進(jìn)程能夠訪問某些設(shè)備。
  • net_cls 子系統(tǒng)兑牡,可以標(biāo)記 cgroups 中進(jìn)程的網(wǎng)絡(luò)數(shù)據(jù)包央碟,然后可以使用 tc 模塊(traffic control)對(duì)數(shù)據(jù)包進(jìn)行控制。
  • freezer 子系統(tǒng)均函,可以掛起或者恢復(fù) cgroups 中的進(jìn)程亿虽。
  • ns 子系統(tǒng),可以使不同 cgroups 下面的進(jìn)程使用不同的 namespace苞也。

每個(gè)子系統(tǒng)都是定義了一套限制策略洛勉,它們需要與內(nèi)核的其他模塊配合來完成資源限制功能,比如對(duì) cpu 資源的限制是通過進(jìn)程調(diào)度模塊根據(jù) cpu 子系統(tǒng)的配置來完成的如迟;對(duì)內(nèi)存資源的限制則是內(nèi)存模塊根據(jù) memory 子系統(tǒng)的配置來完成的收毫,而對(duì)網(wǎng)絡(luò)數(shù)據(jù)包的控制則需要 Traffic Control 子系統(tǒng)來配合完成攻走。

Docker安裝

yum安裝

https://developer.aliyun.com/mirror/docker-ce

# step 1: 安裝必要的一些系統(tǒng)工具
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
# Step 2: 添加軟件源信息
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# Step 3
sudo sed -i 's+download.docker.com+mirrors.aliyun.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
# Step 4: 更新并安裝Docker-CE
sudo yum makecache fast
sudo yum -y install docker-ce
# Step 4: 開啟Docker服務(wù)
sudo service docker start

# 注意:
# 官方軟件源默認(rèn)啟用了最新的軟件,您可以通過編輯軟件源的方式獲取各個(gè)版本的軟件包此再。例如官方并沒有將測(cè)試版本的軟件源置為可用昔搂,您可以通過以下方式開啟。同理可以開啟各種測(cè)試版本等输拇。
# vim /etc/yum.repos.d/docker-ce.repo
#   將[docker-ce-test]下方的enabled=0修改為enabled=1
#
# 安裝指定版本的Docker-CE:
# Step 1: 查找Docker-CE的版本:
yum list docker-ce.x86_64 --showduplicates | sort -r
   Loading mirror speeds from cached hostfile
   Loaded plugins: branch, fastestmirror, langpacks
   docker-ce.x86_64            3:20.10.9-3.el7                     docker-ce-stable
   docker-ce.x86_64            3:20.10.8-3.el7                     docker-ce-stable
   docker-ce.x86_64            3:20.10.7-3.el7                     docker-ce-stable
   docker-ce.x86_64            3:20.10.6-3.el7                     docker-ce-stable
   docker-ce.x86_64            3:20.10.5-3.el7                     docker-ce-stable
   docker-ce.x86_64            3:20.10.4-3.el7                     docker-ce-stable
   docker-ce.x86_64            3:20.10.3-3.el7                     docker-ce-stable
   Available Packages
# Step2: 安裝指定版本的Docker-CE: (VERSION例如上面的17.03.0.ce.1-1.el7.centos)
sudo yum -y install docker-ce.x86_64 3:20.10.12-3.el7


cat /etc/docker/daemon.json
{
  "insecure-registries": ["http://10.0.2.13"],
  "live-restore": true
}

docker 常用命令

https://docs.docker.com/engine/reference/commandline/docker/

# 顯示 Docker 系統(tǒng)信息
docker info

# 拉取 centos:7 鏡像
docker pull centos:7

# 根據(jù)當(dāng)前目錄的Dockerfile構(gòu)建app:v1鏡像
docker build -t app:v1 .

# 在容器 57a77a350082 里執(zhí)行 ls /etc/blackbox_exporter/config.yml 命令
docker exec -it 57a77a350082 ls /etc/blackbox_exporter/config.yml

# 用鏡像nginx:latest 啟動(dòng)容器
docker run --name nginx nginx:latest

# 將容器 57a77a350082 中的 /etc/blackbox_exporter/config.yml 文件復(fù)制到本地 /tmp 目錄下
docker cp 57a77a350082:/etc/blackbox_exporter/config.yml /tmp

# 顯示目前正在運(yùn)行的容器
docker ps

# 顯示當(dāng)前階段所有的容器
docker ps -a

# 停止容器 807a9a776ac6
docker stop 807a9a776ac6

# 顯示容器f49fc00fe206的后100行日志
docker logs -n 100 f49fc00fe206

Harbor

單機(jī)部署

# docker安裝參考上文
# 安裝docker-compose
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod u+x /usr/local/bin/docker-compose

# 下載Harbor離線安裝包 
curl -O -L https://github.com/goharbor/harbor/releases/download/v2.4.1/harbor-offline-installer-v2.4.1.tgz
tar -xzf harbor-offline-installer-v2.4.1.tgz -C /opt/
cd /opt/harbor

# 配置 harbor.yml
harbor]# vi harbor.yml
# 修改主機(jī)名
hostname: 10.0.2.11
# 禁用https訪問
# https:
#  # https port for harbor, default is 443
#  port: 443
#  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path

# 創(chuàng)建數(shù)據(jù)目錄
mkdir /data

# 安裝選項(xiàng)
harbor]# ./install.sh --help

Note: Please set hostname and other necessary attributes in harbor.yml first. DO NOT use localhost or 127.0.0.1 for hostname, because Harbor needs to be accessed by external clients.
Please set --with-notary if needs enable Notary in Harbor, and set ui_url_protocol/ssl_cert/ssl_cert_key in harbor.yml bacause notary must run under https. 
Please set --with-trivy if needs enable Trivy in Harbor
Please set --with-chartmuseum if needs enable Chartmuseum in Harbor

# 執(zhí)行安裝
harbor]# ./install.sh --with-trivy
[Step 0]: checking if docker is installed ...
Note: docker version: 20.10.12
[Step 1]: checking docker-compose is installed ...
Note: docker-compose version: 1.29.2
[Step 2]: loading Harbor images ...
......
[Step 3]: preparing environment ...
......
[Step 4]: preparing harbor configs ...
......
[Step 5]: starting Harbor ...
Creating network "harbor_harbor" with the default driver
......
? ----Harbor has been installed and started successfully.----

HA部署

主機(jī)規(guī)劃

IP 角色
10.0.2.11 harbor-db摘符、redis 、haproxy
10.0.2.12 harbor
10.0.2.13 harbor

所有機(jī)器關(guān)閉防火墻策吠、SELinux

systemctl stop firewalld && systemctl disable firewalld
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=permissive/' /etc/selinux/config

配置外部數(shù)據(jù)庫(kù)

# 和單機(jī)部署一樣逛裤,解壓安裝包
tar -xzf harbor-offline-installer-v2.4.1.tgz -C /opt/
cd /opt/harbor

# 配置 harbor.yml,修改hostname,關(guān)閉https
harbor]# vi harbor.yml
hostname: 10.0.2.11
# https related config
#https:
#  # https port for harbor, default is 443
#  port: 443
#  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path

# 執(zhí)行 ./prepare 腳本猴抹,成功后會(huì)生成 docker-compose.yml 文件
harbor]#  ./prepare

# 修改 docker-compose.yml 文件带族,只保留 log,postgresql,redis 這3個(gè)service,postgresql映射5432端口蟀给,redis映射6379端口
harbor]# cat docker-compose.yml
version: '2.3'
services:
  log:
    image: goharbor/harbor-log:v2.4.1
    container_name: harbor-log
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - SETGID
      - SETUID
    volumes:
      - /var/log/harbor/:/var/log/docker/:z
      - type: bind
        source: ./common/config/log/logrotate.conf
        target: /etc/logrotate.d/logrotate.conf
      - type: bind
        source: ./common/config/log/rsyslog_docker.conf
        target: /etc/rsyslog.d/rsyslog_docker.conf
    ports:
      - 127.0.0.1:1514:10514
    networks:
      - harbor
  postgresql:
    image: goharbor/harbor-db:v2.4.1
    container_name: harbor-db
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - DAC_OVERRIDE
      - SETGID
      - SETUID
    volumes:
      - /data/database:/var/lib/postgresql/data:z
    ports:
      - 5432:5432
    networks:
      harbor:
    env_file:
      - ./common/config/db/env
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "postgresql"
    shm_size: '1gb'
  redis:
    image: goharbor/redis-photon:v2.4.1
    container_name: redis
    restart: always
    cap_drop:
      - ALL
    cap_add:
      - CHOWN
      - SETGID
      - SETUID
    volumes:
      - /data/redis:/var/lib/redis
    ports:
      - 6379:6379
    networks:
      harbor:
    depends_on:
      - log
    logging:
      driver: "syslog"
      options:
        syslog-address: "tcp://localhost:1514"
        tag: "redis"
networks:
  harbor:
    external: false

# 啟動(dòng)數(shù)據(jù)庫(kù)炉菲,默認(rèn)會(huì)初始化 notaryserver,notarysigner,registry 這3個(gè)數(shù)據(jù)庫(kù)
harbor]# docker-compose up -d
harbor]# less /var/log/harbor/postgresql.log
...
harbor-db     | /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/initial-notaryserver.sql
harbor-db     | CREATE DATABASE
harbor-db     | /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/initial-notarysigner.sql
harbor-db     | CREATE DATABASE
harbor-db     | /docker-entrypoint.sh: running /docker-entrypoint-initdb.d/initial-registry.sql
harbor-db     | CREATE DATABASE
harbor-db     | You are now connected to database "registry" as user "postgres".
...

harbor]# docker-compose ps
   Name                 Command                  State                        Ports                  
-----------------------------------------------------------------------------------------------------
harbor-db    /docker-entrypoint.sh 96 13      Up (healthy)   0.0.0.0:5432->5432/tcp,:::5432->5432/tcp
harbor-log   /bin/sh -c /usr/local/bin/ ...   Up (healthy)   127.0.0.1:1514->10514/tcp               
redis        redis-server /etc/redis.conf     Up (healthy)   0.0.0.0:6379->6379/tcp,:::6379->6379/tcp

配置 harbor 節(jié)點(diǎn)

harbor 節(jié)點(diǎn) 除了hostname配置為各自節(jié)點(diǎn)IP,其他配置保持一致

harbor]# vi harbor.yml
# 修改主機(jī)名
hostname: 10.0.2.12

# 關(guān)閉https訪問
# https:
#  # https port for harbor, default is 443
#  port: 443
#  # The path of cert and key files for nginx
#  certificate: /your/certificate/path
#  private_key: /your/private/key/path

# 配置外部數(shù)據(jù)庫(kù)
# Uncomment external_database if using external database.
external_database:
  harbor:
    host: 10.0.2.11
    port: 5432
    db_name: registry
    username: postgres
    password: root123
    ssl_mode: disable
  notary_signer:
    host: 10.0.2.11
    port: 5432
    db_name: notarysigner
    username: postgres
    password: root123
    ssl_mode: disable
  notary_server:
    host: 10.0.2.11
    port: 5432
    db_name: notaryserver
    username: postgres
    password: root123
    ssl_mode: disable

# Uncomment external_redis if using external Redis server
external_redis:
  host: 10.0.2.11:6379
  registry_db_index: 1
  jobservice_db_index: 2
  chartmuseum_db_index: 3
  trivy_db_index: 5
  idle_timeout_seconds: 30

# 執(zhí)行安裝
harbor]# ./install.sh --with-trivy

配置倉(cāng)庫(kù)復(fù)制

先配置 倉(cāng)庫(kù)管理

再配置 復(fù)制管理

圖形界面操作坤溃,參考文檔拍霜,不再一一演示

https://goharbor.io/docs/2.4.0/administration/configuring-replication/

配置Haproxy代理

~]# yum install haproxy -y
 
# 增加 harbor代理配置段
~]# vi /etc/haproxy/haproxy.cfg

# 啟用統(tǒng)計(jì)頁(yè)面
listen stats
    bind  *:9090
    stats enable
    stats uri     /admin?stats
    stats realm HAPorxy\ Stats\ Page
    stats auth admin:admin
    stats admin if TRUE
# harbor 代理
listen harbor
    bind *:80
    mode http
    balance source
    server node02 node02:80 check
    server node03 node03:80 check

harbor-db 備份與恢復(fù)

# 進(jìn)入harbor-db容器
docker exec -it harbor-db bash
postgres [ / ]$ id
uid=999(postgres) gid=999(postgres) groups=999(postgres)
postgres [ / ]$ ls -l /var/lib/postgresql/data
total 4
drwx------. 19 postgres postgres 4096 Dec 28 07:13 pg13

# 執(zhí)行 psql
postgres [ /tmp ]$ psql -U postgres
psql (13.5)
Type "help" for help.

postgres=# \l
                                   List of databases
     Name     |  Owner   | Encoding |   Collate   |    Ctype    |   Access privileges   
--------------+----------+----------+-------------+-------------+-----------------------
 notaryserver | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
              |          |          |             |             | postgres=CTc/postgres+
              |          |          |             |             | server=CTc/postgres
 notarysigner | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres         +
              |          |          |             |             | postgres=CTc/postgres+
              |          |          |             |             | signer=CTc/postgres
 postgres     | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 registry     | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | 
 template0    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
 template1    | postgres | UTF8     | en_US.UTF-8 | en_US.UTF-8 | =c/postgres          +
              |          |          |             |             | postgres=CTc/postgres
(6 rows)

postgres=# \c registry
You are now connected to database "registry" as user "postgres".
registry=# \d 
                         List of relations
 Schema |                Name                |   Type   |  Owner   
--------+------------------------------------+----------+----------
 public | access                             | table    | postgres
 public | access_access_id_seq               | sequence | postgres
 public | alembic_version                    | table    | postgres
 public | artifact                           | table    | postgres
 public | artifact_blob                      | table    | postgres
...
(90 rows)

registry=# select username from harbor_user;
 username  
-----------
 anonymous
 admin
 yangxy
(3 rows)

# 備份數(shù)據(jù)庫(kù)
docker exec harbor-db /bin/sh -c  "pg_dumpall -U postgres -c" > /tmp/dumpall.sql
# 將備份的sql復(fù)制到容器內(nèi)
docker cp /tmp/dumpall.sql harbor-db:/tmp

# 容器內(nèi)執(zhí)行(執(zhí)行數(shù)據(jù)恢復(fù)時(shí)先停掉harbor)
postgres [ /tmp ]$ psql -f dumpall.sql -U postgres
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市薪介,隨后出現(xiàn)的幾起案子祠饺,更是在濱河造成了極大的恐慌,老刑警劉巖汁政,帶你破解...
    沈念sama閱讀 222,378評(píng)論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件道偷,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡记劈,警方通過查閱死者的電腦和手機(jī)勺鸦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,970評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來目木,“玉大人换途,你說我怎么就攤上這事」羯洌” “怎么了军拟?”我有些...
    開封第一講書人閱讀 168,983評(píng)論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)誓禁。 經(jīng)常有香客問我懈息,道長(zhǎng),這世上最難降的妖魔是什么摹恰? 我笑而不...
    開封第一講書人閱讀 59,938評(píng)論 1 299
  • 正文 為了忘掉前任辫继,我火速辦了婚禮怒见,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘姑宽。我一直安慰自己遣耍,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,955評(píng)論 6 398
  • 文/花漫 我一把揭開白布低千。 她就那樣靜靜地躺著,像睡著了一般馏颂。 火紅的嫁衣襯著肌膚如雪示血。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,549評(píng)論 1 312
  • 那天救拉,我揣著相機(jī)與錄音难审,去河邊找鬼。 笑死亿絮,一個(gè)胖子當(dāng)著我的面吹牛告喊,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播派昧,決...
    沈念sama閱讀 41,063評(píng)論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼黔姜,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼!你這毒婦竟也來了蒂萎?” 一聲冷哼從身側(cè)響起秆吵,我...
    開封第一講書人閱讀 39,991評(píng)論 0 277
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎五慈,沒想到半個(gè)月后纳寂,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,522評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡泻拦,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,604評(píng)論 3 342
  • 正文 我和宋清朗相戀三年毙芜,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片争拐。...
    茶點(diǎn)故事閱讀 40,742評(píng)論 1 353
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡腋粥,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出架曹,到底是詐尸還是另有隱情灯抛,我是刑警寧澤,帶...
    沈念sama閱讀 36,413評(píng)論 5 351
  • 正文 年R本政府宣布音瓷,位于F島的核電站对嚼,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏绳慎。R本人自食惡果不足惜纵竖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,094評(píng)論 3 335
  • 文/蒙蒙 一漠烧、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧靡砌,春花似錦已脓、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,572評(píng)論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至画舌,卻和暖如春堕担,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背曲聂。 一陣腳步聲響...
    開封第一講書人閱讀 33,671評(píng)論 1 274
  • 我被黑心中介騙來泰國(guó)打工霹购, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人朋腋。 一個(gè)月前我還...
    沈念sama閱讀 49,159評(píng)論 3 378
  • 正文 我出身青樓齐疙,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親旭咽。 傳聞我的和親對(duì)象是個(gè)殘疾皇子贞奋,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,747評(píng)論 2 361

推薦閱讀更多精彩內(nèi)容