Install docker with cpu/memory restrictions on Debian 8 Jessie

Install prerequisite:

apt-get install libapparmor1

Add sources:

nano /etc/apt/source.list
deb jessie-backports main

Install docker package:

apt-get update 
apt-get install

Add user to docker group:

usermod -aG docker username

Enable adjust memory and swap accounting:

nano /etc/default/grub (edit the following line)
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
shutdown -r now

Example create an R docker:

mkdir ~/dockerfiles && cd ~/dockerfiles
nano Dockerfile
FROM        debian:jessie
MAINTAINER  Siddou <[email protected]>
#add prefered sources
RUN printf "deb jessie main\ndeb-src jessie main\ndeb jessie/updates main\ndeb-src jessie/updates main\ndeb jessie-updates main\ndeb-src jessie-updates main" > /etc/apt/sources.list
#install update/upgrade/packages
RUN apt-get update && apt-get -y upgrade && apt-get install -y \
WORKDIR /home/username/stats

Buid docker:

cd ~/dockerfiles
docker build -t username/r-base .

Run docker:

docker run \
--cpuset-cpus="0-2" \
-m 2048m \
--memory-swap=-1 \
-v ~/stats:/home/username/stats \
-h dockerR \
-it username/r-base:latest

In the run command i added cpu used, memory used, no swap and i define a shared dir between host and docker.

Tagged on: , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *