aramsanのブログ

八方塞がりの年にあえて挑戦し始めるエンジニアリングブログ

Dokcer + CentOS7 環境で tmpfsを使う

以下の形で作成したDockerのインスタンスでそのままではtmpfsが使えなかったので、メモ。

docker pull centos:latest

docker images centos 

 2015/03/05現在 CentOS7がInstallされる

dockerを動かす

docker run -i -t centos /bin/bash

 tmpfsを作る

 [root@xxxx /]# mount -t tmpfs tmpfs /mnt
mount: permission denied

 permissionが足りないらしい。

Dockerでは権限を追加してやるために、Dockerの起動オプションを追加すればうまくいった。

 docker run --privileged -i -t centos /bin/bash

[root@xxxx /]# mount -t tmpfs temps /mnt

 permission deniedがでなくなった!

[root@cb779990271a /]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/docker-xxxx          10190136   251792     9414056 3% /
tmpfs                                              234696             0       234696 0% /dev
shm                                                  65536             0         65536 0% /dev/shm
/dev/mapper/VolGroup-lv_root 201655248 7109996 184295012 4% /etc/hosts
tmpfs                                             234696              0        234696 0% /mnt

 ちゃんとマウントも出来ました。

 

--privileged だと、権限与え過ぎで怖いという方は、SYS_ADMINを付与すると良いようです。

docker run --cap-add=SYS_ADMIN -i -t centos /bin/bash