Skip to content

Instantly share code, notes, and snippets.

@zaenk
Last active April 14, 2017 13:11
Show Gist options
  • Save zaenk/7b831d92039bc833697295a999a7217d to your computer and use it in GitHub Desktop.
Save zaenk/7b831d92039bc833697295a999a7217d to your computer and use it in GitHub Desktop.
Docker on Ubuntu

Determine whether cgroups limit the available memory

  • Create Dockerfile for test
FROM ubuntu:16.04

RUN apt-get update && \
    apt-get install -y openjdk-8-jdk && \
    rm -rf /var/lib/apt/list/*

CMD ["/bin/bash"]
  • Build image
docker build -t j8 .
  • Run with memory constraint:
docker run -it -m 521m --name=java8 j8
  • Check usable memory:
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        161M        950M        153M        868M        1.4G
Swap:          3.8G          0B        3.8G
$ java -XX:+PrintFlagsFinal -version | grep -i heapsize | egrep 'Initial|Max'
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
    uintx InitialHeapSize                          := 33554432                            {product}
    uintx MaxHeapSize                              := 520093696                           {product}
  • Run with other memory constraint:
docker rm j8
docker run -it -m 1024m --name=java8 j8
  • Check usable memory
$ free -h
              total        used        free      shared  buff/cache   available
Mem:           1.9G        162M        949M        153M        867M        1.4G
Swap:          3.8G          0B        3.8G
$ java -XX:+PrintFlagsFinal -version | grep -i heapsize | egrep 'Initial|Max'
openjdk version "1.8.0_121"
OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)
OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)
    uintx InitialHeapSize                          := 33554432                            {product}
    uintx MaxHeapSize                              := 520093696                           {product}

Sources

Installing Docker on Ubuntu

Docker install

  • Remove old versions
sudo apt-get remove docker docker-engine
  • Add docker repositories:
    • Required packages:
    sudo apt-get install \
        apt-transport-https \
        ca-certificates \
        curl \
        software-properties-common
    • Docker's GPG key (validate: sudo apt-key fingerprint 0EBFCD88 should be 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88):
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    • amd64 repository
    sudo add-apt-repository \
     "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
     $(lsb_release -cs) \
     stable"
  • Install
sudo apt-get update
sudo apt-get install docker-ce

Enable "sudoless" docker

sudo groupadd docker
sudo gpasswd -a ${USER} docker # where ${USER} is the username
sudo service docker restart
newgrp docker

Sources

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment