2017-05-06 88 views
0

我正在嘗試使用ECS + EFS(MySQL用於個人站點)執行POC,但文件更改爲docker中已安裝的卷不會使他們去EFS的途徑。ECS + EFS-文件永遠不會出現在容器中

我把它裝在容器主機上:

us-east-1a.fs-#####.efs.us-east-1.amazonaws.com:/ on /mnt/mysql-data-docker type nfs4 (rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=10.0.0.128,local_lock=none,addr=10.0.0.90)

我的任務定義(相關部分)顯示:

"mountPoints": [ 
    { 
    "containerPath": "/var/lib/mysql", 
    "sourceVolume": "mysql-data", 
    "readOnly": null 
    } 
] 

"volumes": [ 
    { 
    "host": { 
     "sourcePath": "/mnt/mysql-data-docker" 
    }, 
    "name": "mysql-data" 
    } 
], 

我可以寫一個文件在那裏,終止主機,讓新的主機通過sc出現並且該文件仍然存在,所以我知道這是行得通的(而且EFS在FS上顯示12kb而不是6kb)。

縱觀運行MySQL容器:

[[email protected] ~]$ docker inspect e96a7 | jq '.[0].Mounts' 
[ 
    { 
    "Source": "/mnt/mysql-data-docker", 
    "Destination": "/var/lib/mysql", 
    "Mode": "", 
    "RW": true, 
    "Propagation": "rprivate" 
    } 
] 

/mnt/mysql-data-docker主機上只顯示我的測試文件,我驗證。在容器中,/var/lib/mysql中有一堆東西,但它永遠不會進入主機或EFS。

回答

1

原來其原因是:

如果你正在使用亞馬遜ECS-AMI優化或亞馬遜的Linux AMI的泊塢窗封裝,多克爾守護進程的坐騎命名空間是從主機的推出在非共享。其他一些AMI也可能有這種行爲。 在其中的任何一個上,文件系統掛載將不會傳播到Docker守護進程,直到下次重新啓動。

因此運行sudo service docker restart && sudo start ecs解決了它。

0

當您啓動,你可以指定在系統啓動時運行「用戶數據」的劇本時,搬運工啓動前

在你的情況EC2實例,這樣的事情應該工作:

#cloud-boothook 
#!/bin/bash 

# Install nfs-utils 
sudo yum install -y nfs-utils 

# Mount EFS, writing the volume to fstab ensures it will automatically mount even on reboot 

    sudo mkdir -p /mnt/mysql-data-docker 
    sudo echo "us-east-1a.fs-#####.efs.us-east-1.amazonaws.com:/ /mnt/mysql-data-docker nfs4 nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2" >> /etc/fstab 

    sudo mount -a 
+0

這不是真的,docker在用戶數據運行之前啓動。我之前的腳本也通過userdata失敗。我發佈的後續答案是確認正在工作 –

+0

這個「魔法」就是用#cloud-boothook。你可以在這裏閱讀更多http://docs.aws.amazon.com/AmazonECS/latest/developerguide/bootstrap_container_instance.html和這裏:https://cloudinit.readthedocs.io/en/latest/topics/format.html –

相關問題