I did some tests in this regard, it looks like the /var/run directory is special in docker.
Here is an example configuration and output:
ubuntu: image: ubuntu command: "bash -c 'mount'" tmpfs: - /var/run - /var/cache
Running docker-compose up ubuntu shows what is being mounted. Can see that /var/cache installed, but /var/run not.
... ubuntu_1 | tmpfs on /var/cache type tmpfs (rw,nosuid,nodev,noexec,relatime) ...
If you use docker-compose run ubuntu bash , you can see that it is also installed there, but not /var/run .
The reason is that /var/run usually a symbolic link to /run , and therefore you create /var/run/mysql as tmpfs does not work.
It will work if you change it to /run/mysql , but /run usually mounted as tmpfs, so you can just do /run tmpfs. For instance:
ubuntu: image: ubuntu command: "bash -c 'mount'" tmpfs: - /run - /var/cache
Note. I would like to modify my answer and show a way to do this using volumes :
services: ubuntu: image: ubuntu command: "bash -c 'mount'" volumes: - cache_vol:/var/cache - run_vol:/run volumes: run_vol: driver_opts: type: tmpfs device: tmpfs cache_vol: driver_opts: type: tmpfs device: tmpfs
It also allows you to share mountable tmpfs .
source share