Debian 9 with Docker

Home » Computer Articles » Linux » Debian 9 with Docker
July 20, 2019 Linux No Comments

Debian 9 setup to become a Docker host server

Download and setup Debian 9 the way you want it.

Docker CE

# curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
# deb [arch=amd64] https://download.docker.com/linux/debian stretch stable

 

Disable some not needed services.

Ref: https://blog.sleeplessbeastie.eu/2015/04/27/how-to-manage-system-services-on-debian-jessie/

# systemctl list-units -t service
# systemctl stop nfs-common.service
# systemctl disable nfs-common.service
# systemctl stop rpcbind.service
# systemctl disable rpcbind.service

 

Update to newer kernel (Optional)

Ref: http://jensd.be/818/linux/install-a-newer-kernel-in-debian-9-stretch-stable

# echo "deb http://ftp.debian.org/debian stretch-backports main" | sudo tee -a /etc/apt/sources.list > /dev/null

# apt-get update
# apt search linux-image
# apt-get -t stretch-backports upgrade
# apt autoremove
# apt-get -t stretch-backports install linux-image-4.19.0-0.bpo.4-amd64

 

Remove old kernel

# dpkg -l | grep linux-image
# apt-get purge linux-image-amd64 linux-image-3.16.0-7-amd64
# update-grub2

 

Search for packages.

# apt-cache search docker

Once you have a package name, you can get more detailed information on the package using the apt-cache show and apt-cache showpkg commands.

# apt-cache show docker-ce
# apt-cache showpkg docker-ce

 

Update the system to the latest version.

# apt update
# apt upgrade

 

After the upgrade is done, you can remove unnecessary packages.

# apt-get autoremove

 

Reboot to updated system

# reboot

 

After the system comes back up, login in and check the Debian version.

# cat /etc/debian_version
# uname -a

 

From docker documentation.

Ref: https://docs.docker.com/install/linux/docker-ce/debian/

# apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common htop
# curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
# apt-key fingerprint 0EBFCD88
# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
# apt-get update
# apt-get install docker-ce
# apt-cache madison docker-ce
# apt-get install docker-ce
# docker run hello-world

 

PIP setup

# apt install python-pip
# pip --version
# pip install --upgrade pip
# pip install docker-compose
# pip install pipdeptree
# pip -V

NOT SURE WHAT TO DO WITH PIP, seems to break all the time when updating. Leave alone.

Ref: https://wakatime.com/blog/22-keeping-your-pip-requirements-fresh

Ref: https://pypi.org/project/pur/

 

Best way to update PIP packages.

# pip freeze > requirements.txt
# pip install pur
# pur -r requirements.txt

 

How to Upgrade All Pip Packages

# pip install --upgrade pip
# pip install -U $(pip freeze | cut -d '=' -f 1)
# pip install --upgrade pip && pip install -U $(pip freeze | cut -d '=' -f 1)

 

Broken PIP Installation

# apt install --reinstall python
# apt purge python-pip
# wget https://bootstrap.pypa.io/get-pip.py
# python get-pip.py

 

Pipdeptree to check all dependencies

# pipdeptree

 

Setup docker

# nano /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="quiet elevator=noop swapaccount=1" or another scheduler deadline or cfq, On VMware noop seems to perform well.

# update-grub2

 

Putting some settings on Docker

nano /etc/docker/daemon.json
{
"storage-driver": "overlay2",
"live-restore": true,
"ipv6": false
}

(Doesn't work on Debian 8 with the 3.16 kernel, needed for 4.9 kernel)

 

Control startup of Docker

nano /lib/systemd/system/docker.service
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock (For production server on the internet)
systemctl reload docker or reboot

 

Check status of Docker

systemctl status docker

 

Cleanup after all updates etc.

rm -rf /usr/share/man/?? && rm -rf /usr/share/man/??_*

 

Add some more settings to sysctl.conf

nano sysctl.conf
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_max_syn_backlog = 8096

 

You should now have a running docker host. Now it's time to start playing with containers.

Share This: