Official Docker Images – Lessons Learned

A presentation at XP Days in December 2018 in Kyiv, Ukraine, 02000 by Philipp Krenn

Slide 1

Slide 1

Official Docker Images Lessons Learned Philipp Krenn @xeraa

Slide 2

Slide 2

Developer

Slide 3

Slide 3

Who uses Docker?

Slide 4

Slide 4

Who uses Docker in production?

Slide 5

Slide 5

Who uses stateful Docker images?

Slide 6

Slide 6

Who uses our images?

Slide 7

Slide 7

Who uses our stack with other images?

Slide 8

Slide 8

Docker: the world's most heavily funded college project Internal quote from Slack

Slide 9

Slide 9

Slide 10

Slide 10

Content "Official" Base Images Release Policy Security & Stability Customization Orchestration

Slide 11

Slide 11

Docker Hub "official"

Slide 12

Slide 12

What do you get? docker pull elasticsearch:X Same for Kibana and Logstash

Slide 13

Slide 13

It's Complicated Docker Inc Deprecated Replicated

Slide 14

Slide 14

Slide 15

Slide 15

Slide 16

Slide 16

Slide 17

Slide 17

Slide 18

Slide 18

Custom Registry docker.elastic.co

Slide 19

Slide 19

I’m surprised more people don’t just host their own container registries since doing that is faster than every cloud offering and docker hub https://twitter.com/jessfraz/status/978449365261082625

Slide 20

Slide 20

Our Motivation Download statistics Speed & reliability

Slide 21

Slide 21

Slide 22

Slide 22

https://www.docker.elastic.co

Slide 23

Slide 23

Problems Some broken tooling like automated builds, Kitematic,... China IPv6

Slide 24

Slide 24

Slide 25

Slide 25

https://hub.docker.com/r/elastic/ elasticsearch/ kibana/ *beat/ logstash/ apm-server/

Slide 26

Slide 26

Base Images

Slide 27

Slide 27

Elasticsearch Alpine

Slide 28

Slide 28

Kibana Beats Logstash Ubuntu

Slide 29

Slide 29

Common base image in 5.4+ CentOS 7

Slide 30

Slide 30

https://github.com/elastic/elasticsearch-docker/blob/master/templates/Dockerfile.j2 FROM centos:7 AS prep_es_files ENV PATH /usr/share/elasticsearch/bin:$PATH RUN curl -s https://download.java.net/java/GA/jdk11/13/GPL/openjdk-11.0.1_linux-x64_bin.tar.gz | \ tar -C /opt -zxf ENV JAVA_HOME /opt/jdk-11.0.1 RUN groupadd -g 1000 elasticsearch && \ adduser -u 1000 -g 1000 -d /usr/share/elasticsearch elasticsearch

Slide 31

Slide 31

PS: Moving Repos in 6.6 / 7.0 https://github.com/elastic/elasticsearch/pull/36246

Slide 32

Slide 32

Upside Similar setup Shared layers JVM large anyway

Slide 33

Slide 33

Slide 34

Slide 34

Downside Size

Slide 35

Slide 35

$ docker images REPOSITORY docker.elastic.co/kibana/kibana docker.elastic.co/elasticsearch/elasticsearch docker.elastic.co/beats/filebeat docker.elastic.co/kibana/kibana docker.elastic.co/elasticsearch/elasticsearch docker.elastic.co/beats/filebeat docker.elastic.co/kibana/kibana docker.elastic.co/elasticsearch/elasticsearch docker.elastic.co/beats/filebeat docker.elastic.co/kibana/kibana docker.elastic.co/elasticsearch/elasticsearch docker.elastic.co/beats/filebeat TAG 6.5.0 6.5.0 6.5.0 6.2.4 6.2.4 6.2.4 5.6.13 5.6.13 5.6.13 5.3.3 5.3.3 5.3.3 IMAGE ID fcc1f039f61c ff171d17e77c aee067f4a241 327c6538ba4c 7cb69da7148d 26a00abcde82 59fcc69d2cc6 21673573a265 2aec30f6b3fc ffe778f7e489 5857f98b5920 c01be8a8f630 SIZE 727MB 774MB 299MB 933MB 515MB 319MB 653MB 525MB 284MB 679MB 165MB 232MB

Slide 36

Slide 36

5.3 5.6 6.2 6.5 ES 165MB 525MB 515MB 774MB Kibana 679MB 653MB 933MB 727MB Filebeat 232MB 284MB 319MB 299MB

Slide 37

Slide 37

Does it matter? stateful vs stateless

Slide 38

Slide 38

What to include?

Slide 39

Slide 39

Single image for 5.x Platinum trial

Slide 40

Slide 40

Three flavors 6.0 to 6.2 * Basic , OSS, Platinum trial * Default

Slide 41

Slide 41

Two flavors 6.3+ * Basic / Platinum trial , OSS * Default

Slide 42

Slide 42

Include Plugins?

Slide 43

Slide 43

Future

Slide 44

Slide 44

Multiple base images?

Slide 45

Slide 45

Even Windows?!

Slide 46

Slide 46

Release Policy

Slide 47

Slide 47

No :latest

Slide 48

Slide 48

Zombies ideas that should have been killed by evidence, but keep shambling along

Slide 49

Slide 49

6 and 6.5?

Slide 50

Slide 50

What's in a tag? docker.elastic.co/elasticsearch/elasticsearch docker.elastic.co/beats/filebeat docker.elastic.co/kibana/kibana 5.3.3 5.3.3 5.3.3 5857f98b5920 c01be8a8f630 ffe778f7e489 4 months ago 5 months ago 5 months ago

Slide 51

Slide 51

Currently Overwrite tag

Slide 52

Slide 52

Label Schema LABEL org.label-schema.schema-version="1.0" \ org.label-schema.vendor="Elastic" \ org.label-schema.name="elasticsearch" \ org.label-schema.version="{{ elastic_version }}" \ org.label-schema.url="https://www.elastic.co/products/elasticsearch" \ org.label-schema.vcs-url="https://github.com/elastic/elasticsearch-docker" \ {% if image_flavor == 'oss' -%} license="Apache-2.0" {% else -%} license="Elastic License" {% endif -%}

Slide 53

Slide 53

Base image & JVM direct dependencies

Slide 54

Slide 54

Future Add image version?

Slide 55

Slide 55

Security & Stability

Slide 56

Slide 56

Run Elasticsearch as root

Slide 57

Slide 57

Cockroaches claims that disappear for a while when proved wrong, but just keep on coming back

Slide 58

Slide 58

Mode Production: Clusterable Development: Local network

Slide 59

Slide 59

"Docker" mode discovery.type=single-node

Slide 60

Slide 60

Bootstrap checks are here to stay

Slide 61

Slide 61

6.0+ no more default credentials

Slide 62

Slide 62

6.x Security non-trial requires certificates

Slide 63

Slide 63

The container runs Elasticsearch as user elasticsearch using uid:gid 1000:1000. https://www.elastic.co/guide/en/elasticsearch/reference/current/ docker.html

Slide 64

Slide 64

Slide 65

Slide 65

Slide 66

Slide 66

Slide 67

Slide 67

Don't mutate the bind mounted local directory

Slide 68

Slide 68

Those who do not understand Unix are condemned to reinvent it, poorly. — Henry Spencer

Slide 69

Slide 69

Docker default value? LimitNOFILE & LimitNPROC

Slide 70

Slide 70

infinity https://github.com/moby/moby/commit/ 8db61095a3d0bcb0733580734ba5d54bc27a614d (July 2016)

Slide 71

Slide 71

Test $ docker run --rm centos:7 /bin/bash -c \ 'ulimit -Hn && ulimit -Sn && ulimit -Hu && ulimit -Su' 1048576 1048576 unlimited unlimited

Slide 72

Slide 72

Limit for virtual memory? vm.max_map_count

Slide 73

Slide 73

Test $ docker run --rm centos:7 /bin/bash -c \ 'sysctl vm.max_map_count' vm.max_map_count = 262144 Must be set on the host

Slide 74

Slide 74

Combine two new systems to get chaos & despair

Slide 75

Slide 75

Docker is a leaky abstraction

Slide 76

Slide 76

Slide 77

Slide 77

Customization

Slide 78

Slide 78

Feature Request if [ -f /custom/user_init.sh ] then . /custom/user_init.sh fi Or customization through environment variables

Slide 79

Slide 79

No Runtime Mutation

Slide 80

Slide 80

Dockerfile ARG ELASTIC_VERSION FROM docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION} RUN bin/elasticsearch-plugin install analysis-phonetic --batch ARG ELASTIC_VERSION RUN bin/elasticsearch-plugin install \ https://github.com/spinscale/elasticsearch-ingest-langdetect/releases/download/ ${ELASTIC_VERSION}.1/ingest-langdetect-${ELASTIC_VERSION}.1.zip --batch

Slide 81

Slide 81

Generate Keystore $ docker run -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" \ -v /Users/philipp/Desktop/demo/config/:/usr/share/elasticsearch/config/ \ -it docker.elastic.co/elasticsearch/elasticsearch:6.5.2 /bin/bash [root@1006ed50b646 elasticsearch]# ./bin/elasticsearch-keystore create Created elasticsearch keystore in /usr/share/elasticsearch/config [root@1006ed50b646 elasticsearch]# ./bin/elasticsearch-keystore add test Enter value for test: [root@1006ed50b646 elasticsearch]# exit exit $ cat config/elasticsearch.keystore ??lelasticsearch.keystore?@g?o!?$?K?Lf?w?VAEŠԨm?[?a6?B??? y?,!В}??Ħ?ǣ?AU=?C?:?o? ?W?O8?}U?;p?ӷ???cQ????7?JY? 2A?:???ZUY??2V?9?ϧ??(??0?q\

Slide 82

Slide 82

Mount Keystore (Docker Compose) elasticsearch: image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION} secrets: - source: elasticsearch.keystore target: /usr/share/elasticsearch/config/elasticsearch.keystore

Slide 83

Slide 83

Orchestration

Slide 84

Slide 84

Who uses Kubernetes?

Slide 85

Slide 85

Who uses Swarm?

Slide 86

Slide 86

Who uses Mesos?

Slide 87

Slide 87

Who uses Nomad?

Slide 88

Slide 88

No orchestration yet

Slide 89

Slide 89

Kubernetes 1.8 allows dots in env vars https://github.com/kubernetes/kubernetes/issues/2707

Slide 90

Slide 90

Slide 91

Slide 91

Slide 92

Slide 92

Kubernetes has made huge improvements in the ability to run stateful workloads including databases and message queues, but I still prefer not to run them on Kubernetes. https://twitter.com/kelseyhightower/status/963413508300812295

Slide 93

Slide 93

Slide 94

Slide 94

Conclusion

Slide 95

Slide 95

"Docker is disrupting the industry"

Slide 96

Slide 96

"Can I run Elasticsearch on Docker?"

Slide 97

Slide 97

"Should I run Elasticsearch on Docker?"

Slide 98

Slide 98

Even when stateful services do the right things managing state is still hard. Mixing stateful and stateless applications on the same cluster elevates the complexity of the entire cluster. Cluster security and upgrades become much harder. https://twitter.com/kelseyhightower/status/963417215608369153

Slide 99

Slide 99

Quick Quiz What do you get?

Slide 100

Slide 100

docker pull elastic/elasticsearch

Slide 101

Slide 101

$ docker pull elastic/elasticsearch Using default tag: latest Error response from daemon: manifest for elastic/elasticsearch:latest not found

Slide 102

Slide 102

docker pull logstash:alpine

Slide 103

Slide 103

docker pull metricbeat:6.5.2

Slide 104

Slide 104

$ docker pull metricbeat:6.5.2 Error response from daemon: pull access denied for metricbeat, repository does not exist or may require 'docker login'

Slide 105

Slide 105

docker pull elastic/metricbeat:6.5.2

Slide 106

Slide 106

docker pull docker.elastic.co/apm/apm-server:6.5.2

Slide 107

Slide 107

Questions & Discussion Philipp Krenn @xeraa