Docker best practices

9th of September, 2017 in link

Reference & summary of docker best practices

  1. Docker
    1. Installation
      1. Debian
        1. Update the apt-get package index
        2. Install packages to use a repository over HTTPS
        3. Add Docker’s official GPG key
        4. Verify the fingerprint (last 8 characters)
        5. Setup the stable docker repository
        6. Update the apt-get package index
        7. Install docker
        8. Setup proxy
          1. Edit the file /etc/default/docker and modify the proxy settings
          2. Restart the docker service
        9. Run the hello-world image
        10. If not working
    2. Usage
      1. Build image with a custom name
  2. Docker compose
    1. Installation
      1. Debian
        1. Download latest package
        2. Apply executable permissions
        3. Test the installation
    2. Usage
  3. Sources

Docker

Installation

Debian

Update the apt-get package index
1
sudo apt-get update
Install packages to use a repository over HTTPS
1
2
3
4
5
6
sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     software-properties-common
Add Docker’s official GPG key
1
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg | sudo apt-key add -
Verify the fingerprint (last 8 characters)
1
sudo apt-key fingerprint 0EBFCD88
Setup the stable docker repository
1
2
3
4
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
   $(lsb_release -cs) \
   stable"
Update the apt-get package index
1
sudo apt-get update
Install docker
1
2
3
4
sudo apt-get install docker-ce                  # Latest version
apt-cache madison docker-ce                     # List available versions
                                                # (use 2nd column as VERSION_STRING)
sudo apt-get install docker-ce=<VERSION_STRING> # Install specific version.

The Docker daemon starts automatically.

Setup proxy
Edit the file /etc/default/docker and modify the proxy settings
Restart the docker service
1
service docker restart
Run the hello-world image
1
sudo docker run hello-world
If not working
1
2
3
4
/etc/systemd/system/docker.service.d/http-proxy.conf
/etc/systemd/system/docker.service.d/https-proxy.conf
sudo systemctl daemon-reload       # Flush changes
sudo systemctl restart docker      # Restart docker service

Usage

Build image with a custom name

1
docker build -t customName .

Docker compose

Installation

Debian

Download latest package
1
sudo curl -L https://github.com/docker/compose/releases/download/1.16.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
Apply executable permissions
1
sudo chmod +x /usr/local/bin/docker-compose
Test the installation
1
2
$ docker-compose --version
docker-compose version 1.16.1, build 1719ceb

Usage

todo

Sources

Get Docker CE for Debian

RHD Blog - 10 things to avoid in docker containers
@rafabene - twitter