docker外掛nfs存儲

  一、nfs安裝

  1、安裝依賴

yum -y install nfs-utils rpcbind

  2、設定目錄

mkdir /nfs -p
chmod 777 /nfs

  3、創建 exports 

vi /etc/exports

  加入:

/nfs *(rw,insecure,sync,no_subtree_check,no_root_squash)

  生效

exportfs -r # 生效
exportfs  #查看

  4、重啓服務

systemctl restart rpcbind && systemctl enable rpcbind
systemctl restart nfs && systemctl enable nfs

  5、檢查 nfs 服務器

showmount -e 192.168.5.14

  6、本地測試客戶端

mount -t nfs 192.168.5.14:/nfs /nfs_share

  

  二、docker掛載

version: '3'
services:
  xbd-mysql:
    image: mysql:8.0.19
    restart: always
    container_name: xbd-mysql
    volumes:
      - nfs:/var/lib/mysql
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: root
    privileged: true
    command: ['--lower_case_table_names=1', '--character-set-server=utf8', '--collation-server=utf8_general_ci']

volumes:
  nfs:
    driver_opts:
      type: "nfs"
      o: "addr=192.168.5.14,nolock,soft,rw"
      device: ":/nfs/mysql"

  測試:

  

 

   也可以通過docker的方式創建volume

docker volume create nfs_name -d local -o type=nfs -o o=addr=192.168.5.14,nolock,soft,rw -o device=:/nfs/mysql

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章