P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ......
Transcript of P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ......
![Page 1: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/1.jpg)
PostgreSQL and variations of linux containers
Honza Horak <[email protected]>P2D2, Praha, February 2017
![Page 2: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/2.jpg)
PostgreSQL and variations of linux containers
The goal today
● Show how we think about containers● Convince you that you shouldn’t ignore them● Introduce technologies that we care about in Red Hat● Get feedback
![Page 3: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/3.jpg)
PostgreSQL and variations of linux containers
Honza HorakBrno, Czech Republic
● Red Hat, Platform Engineering● Databases, Python, Ruby● RHEL, Fedora, CentOS● Software Collections
![Page 4: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/4.jpg)
PostgreSQL and variations of linux containers
Honza HorakBrno, Czech Republic
● Red Hat, Platform Engineering● Databases, Python, Ruby● RHEL, Fedora, CentOS● Software Collections● AND CONTAINERS
![Page 5: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/5.jpg)
PostgreSQL and variations of linux containers
What this talk includes
1. Containers basics2. PostgreSQL Docker container3. Standalone containers4. Tools containers5. GUI apps in containers6. OS containers7. Ansible Containers8. OCI
![Page 6: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/6.jpg)
PostgreSQL and variations of linux containers
1. CONTAINERS BASICS
![Page 7: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/7.jpg)
![Page 8: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/8.jpg)
PostgreSQL and variations of linux containers
Containers and images
● Container aka Docker○ Process isolated by Linux kernel features
■ cgroups, namespaces, SELinux, …○ Virtualization technology
● Image○ Static container used to run containers
● Container is an instance of a (container) image
![Page 9: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/9.jpg)
PostgreSQL and variations of linux containers
Container is not a virtual machine
Infrastructure
Host OS (kernel)
Container Engine (Docker daemon)
Bin/Libs Bin/Libs Bin/Libs
App App App
Linux Containers (e.g. Docker)
Infrastructure
Host OS (kernel)
Hypervisor
Bin/Libs Bin/Libs Bin/Libs
App App App
Guest OS Guest OS Guest OS
Traditional Virtual Machine
![Page 10: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/10.jpg)
PostgreSQL and variations of linux containers
Container is not a virtual machine
Infrastructure
Host OS (kernel)
Docker Engine
Bin/Libs Bin/Libs Bin/Libs
App App App
Linux Containers (e.g. Docker)
Infrastructure
Host OS (kernel)
Hypervisor
Bin/Libs Bin/Libs Bin/Libs
App App App
Guest OS Guest OS Guest OS
Traditional Virtual Machine
![Page 11: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/11.jpg)
PostgreSQL and variations of linux containers
Container is not a virtual machine
Infrastructure
Host OS (kernel)
Docker Engine
Bin/Libs Bin/Libs Bin/Libs
App App App
Linux Containers (e.g. Docker)
Infrastructure
Host OS (kernel)
Hypervisor
Bin/Libs Bin/Libs Bin/Libs
App App App
Guest OS Guest OS Guest OS
Traditional Virtual Machine
![Page 12: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/12.jpg)
PostgreSQL and variations of linux containers
Container is not a virtual machine
Infrastructure
Host OS (kernel)
Docker Engine
Bin/Libs Bin/Libs Bin/Libs
App App App
Linux Containers (e.g. Docker)
Infrastructure
Host OS (kernel)
Hypervisor
Bin/Libs Bin/Libs Bin/Libs
App App App
Guest OS Guest OS Guest OS
Traditional Virtual Machine
![Page 13: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/13.jpg)
PostgreSQL and variations of linux containers
Container is not a virtual machine
Infrastructure
Host OS (kernel)
Docker Engine
Bin/Libs Bin/Libs Bin/Libs
App App App
Linux Containers (e.g. Docker)
Infrastructure
Host OS (kernel)
Hypervisor
Bin/Libs Bin/Libs Bin/Libs
App App App
Guest OS Guest OS Guest OS
Traditional Virtual Machine
![Page 14: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/14.jpg)
Use only content you trust.
![Page 15: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/15.jpg)
Avoid root inside containeror use user namespaces.
![Page 16: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/16.jpg)
![Page 17: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/17.jpg)
PostgreSQL and variations of linux containers
Docker and LayersWhat is gonna be part of distribution and what is beyond.
MyApp DB Master
RHEL Base Image 7.3
Python 3.5
Django App
PHP + Apache
Wordpress
PostgreSQL
MyApp DB Slave
Dis
tribu
tion
Dev
Ops
MyApp DB Backup NodeBlog
![Page 18: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/18.jpg)
PostgreSQL and variations of linux containers
Docker and LayersWhat is gonna be part of distribution and what is beyond.
MyApp DB Master
RHEL Base Image 7.3
Python 3.5
Django App
PHP + Apache
Wordpress
PostgreSQL
MyApp DB Slave
Dis
tribu
tion
Dev
Ops
MyApp DB Backup NodeBlog
glibc fix
![Page 19: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/19.jpg)
PostgreSQL and variations of linux containers
Docker and LayersWhat is gonna be part of distribution and what is beyond.
MyApp DB Master
RHEL Base Image 7.3
Python 3.5
Django App
PHP + Apache
Wordpress
PostgreSQL
MyApp DB Slave
Dis
tribu
tion
Dev
Ops
MyApp DB Backup NodeBlog
glibc fix
![Page 20: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/20.jpg)
PostgreSQL and variations of linux containers
Docker and LayersWhat is gonna be part of distribution and what is beyond.
MyApp DB Master
RHEL Base Image 7.3
Python 3.5
Django App
PHP + Apache
Wordpress
PostgreSQL
MyApp DB Slave
Dis
tribu
tion
Dev
Ops
MyApp DB Backup NodeBlog
glibc fix
![Page 21: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/21.jpg)
PostgreSQL and variations of linux containers
Docker and LayersWhat is gonna be part of distribution and what is beyond.
MyApp DB Master
RHEL Base Image 7.3
Python 3.5
Django App
PHP + Apache
Wordpress
PostgreSQL
MyApp DB Slave
Dis
tribu
tion
Dev
Ops
MyApp DB Backup NodeBlog
glibc fix
![Page 22: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/22.jpg)
Automate.
![Page 23: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/23.jpg)
Automate.Everything.
![Page 24: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/24.jpg)
PostgreSQL and variations of linux containers
Containers in Red Hat ...end in OpenShift, a PaaS based on kubernetes (k8s)
https://blog.openshift.com/red-hat-container-platform-3-3-general-availability/
![Page 25: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/25.jpg)
PostgreSQL and variations of linux containers
2. POSTGRESQL DOCKER CONTAINER
![Page 26: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/26.jpg)
Why actually?
![Page 27: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/27.jpg)
It’s about efficiency.But not about efficiency of sharing
resources, it’s about efficiency of whole organization.
It’s about new thinking, a whole new paradigm.
![Page 28: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/28.jpg)
Real Docker Adoption Is Up 30% in One Year.
https://www.datadoghq.com/docker-adoption/
![Page 29: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/29.jpg)
Real Docker Adoption Is Up 30% in One Year.2/3 of Companies That Try Docker Adopt It.
https://www.datadoghq.com/docker-adoption/
![Page 30: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/30.jpg)
Real Docker Adoption Is Up 30% in One Year.2/3 of Companies That Try Docker Adopt It.
PostgreSQL is 9th mostly used container image, using Docker to run relational databases is surprisingly
common.https://www.datadoghq.com/docker-adoption/
![Page 31: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/31.jpg)
PostgreSQL and variations of linux containers
#> cat Dockerfile
FROM rhel7:7.3
RUN yum -y install postgresql-server && \ yum clean all
Building own PostgreSQL container
31
![Page 32: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/32.jpg)
PostgreSQL and variations of linux containers
#> docker build -t hhorak/postgresql .…
Build the container
32
![Page 33: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/33.jpg)
PostgreSQL and variations of linux containers
#> docker build -t hhorak/postgresql .…
#> docker run -ti hhorak/postgresqlbash-4.2$ _
Correct RPMs are in a container
33
![Page 34: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/34.jpg)
PostgreSQL and variations of linux containers
#> docker build -t hhorak/postgresql .…
#> docker run -ti hhorak/postgresqlbash-4.2$ rpm -q postgresql-serverpostgresql-server-9.2.18-1.el7.x86_64
Correct RPMs are in a container
34
![Page 35: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/35.jpg)
So we have PostgreSQL in a Linux container.
Are we there yet?
![Page 36: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/36.jpg)
PostgreSQL and variations of linux containers
#> cat Dockerfile
FROM rhel7:7.3
RUN yum -y install postgresql-server && yum clean all
ENV HOME=/var/lib/pgsqlENV PGDATA=/var/lib/pgsql/dataENV PGUSER=postgresUSER 26
COPY run-postgresql /usr/bin/CMD [ "/usr/bin/run-postgresql" ]
Make container do something
36
![Page 37: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/37.jpg)
PostgreSQL and variations of linux containers
#> cat run-postgresql
#!/bin/bash
initdb
echo "host all all 0.0.0.0/0 md5" >${PGDATA}/pg_hba.confecho "listen_addresses = '*'" >${PGDATA}/postgresql.conf
exec postgres "$@"
Make container do something
37
Who said microservice?
![Page 38: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/38.jpg)
PostgreSQL and variations of linux containers
#> docker build -t hhorak/postgresql .
#> docker run -ti -p 5432:5432 --name p1 hhorak/postgresql
#> docker inspect --format='{{.NetworkSettings.IPAddress}}' p1172.17.0.2
#> psql -h 172.17.0.2Password: _
Connecting to PostgreSQL container
38
![Page 39: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/39.jpg)
PostgreSQL and variations of linux containers
#> docker build -t hhorak/postgresql .
#> docker run -ti -p 5432:5432 --name p1 hhorak/postgresql
#> docker inspect --format='{{.NetworkSettings.IPAddress}}' p1172.17.0.2
#> psql -h 172.17.0.2Password: _
Connecting to PostgreSQL container
39
![Page 40: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/40.jpg)
Do not use default passwords.
![Page 41: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/41.jpg)
PostgreSQL and variations of linux containers
#> cat run-postgresql
...echo "host all all 0.0.0.0/0 md5" >${PGDATA}/pg_hba.confecho "local all postgres peer" >>${PGDATA}/pg_hba.confecho "listen_addresses = '*'" >${PGDATA}/postgresql.conf
pg_ctl -w start -o "-h ''"psql --command "ALTER USER \"postgres\" WITH ENCRYPTED PASSWORD '${POSTGRESQL_ADMIN_PASSWORD}';"pg_ctl stop
exec postgres "$@"
Connecting to PostgreSQL container
41
![Page 42: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/42.jpg)
PostgreSQL and variations of linux containers
#> docker run -ti -p 5432:5432 --name p1 hhorak/postgresql
#> psql -h 172.17.0.2 -U postgresPassword for user postgres:psql (9.2.18, server 9.2.18)Type "help" for help.
postgres=# _
Connecting to PostgreSQL container
42
![Page 43: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/43.jpg)
PostgreSQL and variations of linux containers
if [ -e "/run/secrets/pgusers/user/username" ] ; then POSTGRESQL_USER="$(</run/secrets/pgusers/user/username)" POSTGRESQL_PASSWORD="$(</run/secrets/pgusers/user/password)"fi
Or use k8s secrets
43
http://kubernetes.io/docs/user-guide/secrets/
![Page 44: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/44.jpg)
How to configure such a database?
![Page 45: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/45.jpg)
PostgreSQL and variations of linux containers
#> cat run-postgresql...echo "max_connections = ${POSTGRESQL_MAX_CONNECTIONS}" >>${PGDATA}/postgresql.conf...
Configuring PostgreSQL container
45
![Page 46: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/46.jpg)
PostgreSQL and variations of linux containers
Example of PostgreSQL 9.5 containerfrom Red Hat Software Collections
#> docker run -d \ -p 5432:5432 \ -e POSTGRESQL_ADMIN_PASSWORD=secret \ -e POSTGRESQL_MAX_CONNECTIONS=10 \ -e POSTGRESQL_USER=guestbook \ -e POSTGRESQL_PASSWORD=pass \ -e POSTGRESQL_DATABASE=guestbook \ -v /db:/var/lib/pgsql/data:Z \ rhscl/postgresql-95-rhel7
46
![Page 47: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/47.jpg)
PostgreSQL and variations of linux containers
Auto-tuning in PostgreSQL containerContainers may be slim or fat.
# Get available memory for containerMEMORY_IN_BYTES=$(cat /sys/fs/cgroup/memory/memory.limit_in_bytes)
# Use 1/4 of given memory for shared buffersPOSTGRESQL_SHARED_BUFFERS="$(($MEMORY_IN_BYTES/1024/1024/4))MB" # Setting effective_cache_size to 1/2 of total memoryPOSTGRESQL_EFFECTIVE_CACHE_SIZE="$(($MEMORY_IN_BYTES/1024/1024/2))MB"
# postgresql.conf is later generated as:shared_buffers = ${POSTGRESQL_SHARED_BUFFERS}effective_cache_size = ${POSTGRESQL_EFFECTIVE_CACHE_SIZE}
47
![Page 48: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/48.jpg)
Support the most common configuration (let users to change them in OpenShift)
and allow users to build their own specific layered container images easily.
![Page 49: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/49.jpg)
For working code, see:https://github.com/sclorg/postgresql-container
![Page 50: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/50.jpg)
For working code, see:https://github.com/sclorg/postgresql-container
And contribute!
![Page 51: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/51.jpg)
PostgreSQL and variations of linux containers
Or play with container directly
#> docker pull centos/postgresql-94-centos7#> docker pull centos/postgresql-95-centos7
#> docker pull registry.access.redhat.com/rhscl/postgresql-94-rhel7#> docker pull registry.access.redhat.com/rhscl/postgresql-95-rhel7
51
![Page 52: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/52.jpg)
Q: What do I want to look at closely when I want to run 100 containers?
![Page 53: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/53.jpg)
PostgreSQL and variations of linux containers
3. STANDALONE CONTAINER
![Page 54: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/54.jpg)
PostgreSQL and variations of linux containers
Run container as systemd serviceAlias replace a classic system service with a container
Handy for transition period
● Part of the services as containers, rest as standard services
We need to:
1. Create Docker container2. Create systemd unit file for the service3. Work with the systemd unit as usually
![Page 55: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/55.jpg)
PostgreSQL and variations of linux containers
#> docker create --name postgresql-service -e … -v /var/lib/pgsql:/var/lib/pgsql:Z fedora/postgresql
Run container as systemd service1. Create Docker container (but not run)
![Page 56: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/56.jpg)
PostgreSQL and variations of linux containers
# cat /etc/systemd/system/postgresql-cont.service[Unit]Description=PostgreSQL service as a docker containerAfter=docker.service
[Service]ExecStart=/usr/bin/docker start postgresql-contExecStop=/usr/bin/docker stop postgresql-cont
[Install]WantedBy=multi-user.target
Run container as systemd service2. Create systemd unit file for the service
![Page 57: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/57.jpg)
PostgreSQL and variations of linux containers
#> systemctl enable postgresql-cont.service#> systemctl start postgresql-cont.service
Run container as systemd service3. Work with the systemd service as usually
![Page 58: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/58.jpg)
Q: Is it possible to run a container as a systemd service?
![Page 59: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/59.jpg)
PostgreSQL and variations of linux containers
4. TOOLS CONTAINERS
![Page 60: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/60.jpg)
Not every container is a daemon
![Page 61: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/61.jpg)
PostgreSQL and variations of linux containers
#> docker run -ti hhorak/postgresql-tools pgbench …
#> docker run -ti hhorak/postgresql-tools pg_standby …
Tools to manage daemons(that are not part of the daemon image)
Interaction is easy, we can use network socket to work with daemon.
![Page 62: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/62.jpg)
PostgreSQL and variations of linux containers
#> docker exec -ti postgresql1 pg_dump >/home/hhorak/dump.sql
How to interact with host
#> docker run -ti -v /:/host hhorak/postgresql bashbash-4.2$ pg_dump >/host/home/hhorak/dump.sqlbash-4.2$ ...
![Page 63: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/63.jpg)
Q: Is it possible to use containers for non-deamon applications?
![Page 64: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/64.jpg)
PostgreSQL and variations of linux containers
5. GUI APPS IN CONTAINERS
![Page 65: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/65.jpg)
PostgreSQL and variations of linux containers
Why GUI in containers
● Some level of isolation○ Filesystem, Cgroups, Namespaces
● Deps bundling →one app running on any Linux● Android-like app store for all distros● Clean system underneath
![Page 66: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/66.jpg)
PostgreSQL and variations of linux containers
GUI in DockerWell, it sometimes even works, but..
docker run -ti --rm \ -e DISPLAY=$DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -u 1001 \ hhorak/pgadmin3
![Page 67: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/67.jpg)
PostgreSQL and variations of linux containers
GUI in Flatpak
● Designed for GUI apps● Sandbox rather than full container● Runtimes define common environment to build on● Runs in desktop session
aka xdg-app
![Page 68: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/68.jpg)
PostgreSQL and variations of linux containers
Flatpak design
http://flatpak.org/#developers
68
![Page 69: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/69.jpg)
PostgreSQL and variations of linux containers
Working with Flatpak applicationhttp://flatpak.org/developer.html
$ tar xvf pgadmin3-1.22.1.tar.gz$ cd pgadmin3-1.22.1
$ flatpak build ../dictionary ./configure --prefix=/app$ flatpak build ../dictionary make$ flatpak build ../dictionary make install
69
$ flatpak install gnome org.gnome.Platform 3.22$ flatpak install gnome-apps org.postgresql.pgadmin3 stable
$ flatpak run org.postgresql.pgadmin3
![Page 70: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/70.jpg)
Q: What type of applications Flatpack is designed for?
![Page 71: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/71.jpg)
PostgreSQL and variations of linux containers
6. OS CONTAINERS
![Page 72: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/72.jpg)
PostgreSQL and variations of linux containers
MultiContainer vs. OS Container
VS
![Page 73: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/73.jpg)
PostgreSQL and variations of linux containers
Operating System Container
● Some applications work better when running on one machine● Safe zombie handling● Container’s journald integration
Running whole OS (systemd or other init process) inside container.
![Page 74: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/74.jpg)
PostgreSQL and variations of linux containers
Running systemd inside Dockerhttp://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container
docker run -ti --tmpfs /run --tmpfs /tmp -v /sys/fs/cgroup:/sys/fs/cgroup:ro <your-image>
74
FROM fedora:25RUN dnf -y install postgresql-server && dnf clean allRUN systemctl enable postgresqlSTOPSIGNAL SIGRTMIN+3EXPOSE 80CMD [ "/sbin/init" ]
![Page 75: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/75.jpg)
PostgreSQL and variations of linux containers
OS Container using systemd-nspawn
● better connection with host (logging, machinectl, ...)● no image management, no containers linking● good enough for testing or debugging something at container level
Running whole OS (including systemd) inside container.
![Page 76: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/76.jpg)
PostgreSQL and variations of linux containers
Running systemd inside nspawnhttps://www.variantweb.net/blog/using-systemd-nspwan-for-lightweight-container-in-fedora-21/
dnf -y --releasever=25 --nogpg --installroot=/var/tmp/testnspawn --disablerepo='*' --enablerepo=fedora --enablerepo=updates install systemd passwd yum fedora-release postgresql-server @standardchcon -R -t svirt_sandbox_file_t /var/tmp/testnspawnrestorecon -R /var/tmp/testnspawn
76
systemd-nspawn -D /var/tmp/testnspawnpasswdpostgresql-setup --initsystemctl enable postgresql
systemd-nspawn -bD /var/tmp/testnspawn
![Page 77: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/77.jpg)
Q: Is it possible to run docker image in systemd-nspawn?
![Page 78: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/78.jpg)
Who likes Ansible?
![Page 79: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/79.jpg)
PostgreSQL and variations of linux containers
7. Ansible containers
![Page 80: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/80.jpg)
PostgreSQL and variations of linux containers
Ansible containers
● Building containers using popular Ansible● Orchestrating containers like other services● Especially useful for transition to containers
![Page 81: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/81.jpg)
PostgreSQL and variations of linux containers
Ansible Container https://github.com/ansible/ansible-container-examples/tree/master/wordpress
81
services: db: image: rhel:7 ports: - "5432:5432" command: ['/usr/bin/pg_ctl', '-w', 'start'] wordpress: image: rhel:7 ports: - "80:80" links: - dbcommand: bash -c "bash /tmp/a.sh ; usr/sbin/apachectl -D FOREGROUND"
![Page 82: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/82.jpg)
PostgreSQL and variations of linux containers
Ansible container - name: postgresql-init shell: postgresql-setup --upgrade
- name: run postgres shell: pg_ctl -w start - name: Create postgres database pgsql_db: name: "{{ wp_pgsql_db }}" state: present - name: Create postgres user pgsql_user: name: "{{ wp_pgsql_user }}" password: "{{ wp_pgsql_password }}" state: present priv: "*.*:ALL,GRANT" host: "%"
- hosts: db vars: - wp_pgsql_db: wordpress - wp_pgsql_user: wordpress - wp_pgsql_password: password tasks: - name: Install postgresql-server yum: name: "{{ item }}" state: latest with_items: - postgresql-server
- name: Update the repository shell: yum -y erase vim-minimal && \ yum -y update && \ yum clean all
![Page 83: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/83.jpg)
PostgreSQL and variations of linux containers
Ansible Container https://github.com/ansible/ansible-container-examples/tree/master/wordpress
83
$> ansible-container init -- do changes -- $> ansible-container build $> ansible-container run $> docker login $> ansible-container push $> ansible-container shipit openshift
![Page 84: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/84.jpg)
PostgreSQL and variations of linux containers
8. OCI
![Page 85: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/85.jpg)
PostgreSQL and variations of linux containers
8. OCIOpen Container Initiative
![Page 86: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/86.jpg)
PostgreSQL and variations of linux containers
Docker
rktAnsiblecontainer
nspawn
![Page 87: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/87.jpg)
PostgreSQL and variations of linux containers
"The mission of the OCI is to promote and promulgate
a set of common, minimal, open standards
and specifications around container technology."
https://www.opencontainers.org
![Page 88: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/88.jpg)
PostgreSQL and variations of linux containers
Open Container InitiativeCollaboration of Red Hat, Google, Docker, and others big players in containers world.
● Image tools - https://github.com/opencontainers/image-tools ● runc - https://github.com/opencontainers/runc ● Open Container Format
![Page 89: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/89.jpg)
Q: Will I build my container today?
![Page 90: P2D2, Praha, February 2017 Honza Horak Introduce technologies that we care about in Red Hat ... Docker Engine Bin/Libs Bin/Libs Bin/Libs App App App Linux](https://reader036.fdocuments.in/reader036/viewer/2022071113/5fe980e483491352460c8a77/html5/thumbnails/90.jpg)
Thanks.
OpenShift: https://docs.openshift.com Sources of Docker images: https://github.com/sclorg/Project Atomic: https://www.projectatomic.io OCI: https://www.opencontainers.org/
Honza Horak <[email protected]>@HonzaHorak