Bojan Vukasovic
Bojan Vukasovic

Reputation: 2268

Docker container with it's own disk and memory

I wanted to test my app inside docker container for the case when disk is 100% full, or when all system file-descriptors are used, or when memory is used 100% etc...

Is it possible to do this inside docker container? So far I can see that when 'df' command is executed, it shows size of the host system and not docker container one.

I just wanted to specify e.g. 1GB HDD and 1GB RAM, and then use some app to fill the disk and memory for testing.

Upvotes: 0

Views: 246

Answers (1)

jlonganecker
jlonganecker

Reputation: 1198

Have you tried:

Create Volume


docker volume create --driver local \
    --opt type=tmpfs \
    --opt device=tmpfs \
    --opt o=size=1g,uid=1000 \
    my-new-volume

Run Container with new Volume


docker run -d -v my-new-volume:/in-container-location container-image

Have your app write to /in-container-location


Source - https://docs.docker.com/engine/reference/commandline/volume_create/#examples

Memory


docker run -d --memory="1g" container-image

source - https://docs.docker.com/config/containers/resource_constraints/#memory

Mix the two


docker run -d --memory="1g" -v my-new-volume:/in-container-location container-image

Upvotes: 2

Related Questions