大网数据广告活动
服务器运维问答

Mount a new volume into a docker instance

· 52CE 我爱测

I have a web site running in a docker instance. The site has a documents folder that needs more storage. So, I created a new volume on AWS. I can see it from the host with lsblk , like so: $ sudo lsblk NAME MAJ:MIN RM SIZE RO TYP…

问题原文

原帖链接 · James John McGuire 'Jahmic' · CC BY-SA 4.0

I have a web site running in a docker instance. The site has a documents folder that needs more storage. So, I created a new volume on AWS. I can see it from the host with lsblk, like so:

$ sudo lsblk
NAME    MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda    202:0    0   8G  0 disk
└─xvda1 202:1    0   8G  0 part /
xvdf    202:80   0  20G  0 disk

Within the web site structure, inside the docker container, I would like to mount the disk to:

/var/www/localhost/htdocs/sites/default/documents/

Normally, I would just use the following:

sudo mount /dev/xvdf /var/www/localhost/htdocs/sites/default/documents/

But since it is in a docker container, I'm a bit confused on how to connect it. How can I mount the drive to the given directory?

Docker is quite new to me. I barely heard of it until a few weeks ago. I have control to sh into the container and also restart it.

已采纳解答

原帖链接 · James John McGuire 'Jahmic' · CC BY-SA 4.0

Finally, figured it out.

First, I had to track down how the instance was started in the first place. By this command:

./docker-compose up -d --build

In that same directory, there was a docker-compose.yml file, so I added the following line, in the main service ( and not top level):

- /mnt:/var/www/localhost/htdocs/sites/default/documents

Stopped the instance Mounted the drive:

sudo mount /dev/xvdf /mnt

Restarted the container:

./docker-compose up -d --build

shelled into the docker instance, and verified volume mounted with:

df

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-08-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。