siddou.tk

Install docker with cpu/memory restrictions on Debian 8 Jessie

Install prerequisite:

apt-get install libapparmor1

Add sources:

nano /etc/apt/source.list
deb http://http.debian.net/debian jessie-backports main

Install docker package:

apt-get update 
apt-get install docker.io

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"
update-grub
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 http://ftp.fr.debian.org/debian/ jessie main\ndeb-src http://ftp.fr.debian.org/debian/ jessie main\ndeb http://security.debian.org/ jessie/updates main\ndeb-src http://security.debian.org/ jessie/updates main\ndeb http://ftp.fr.debian.org/debian/ jessie-updates main\ndeb-src http://ftp.fr.debian.org/debian/ jessie-updates main" > /etc/apt/sources.list
#install update/upgrade/packages
RUN apt-get update && apt-get -y upgrade && apt-get install -y \
    r-base
#
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 *