From 38ec9cecbac84d91a33ce9416c6afeb2c6672a70 Mon Sep 17 00:00:00 2001 From: Leon Stoldt Date: Sat, 7 Aug 2021 14:35:02 +0200 Subject: [PATCH 1/5] Added Pi-hole / cloudflared example for use of DoH Signed-off-by: Leon Stoldt --- README.md | 1 + pihole-cloudflared-DoH/.env | 8 ++ pihole-cloudflared-DoH/README.md | 108 +++++++++++++++++++++ pihole-cloudflared-DoH/docker-compose.yaml | 55 +++++++++++ 4 files changed, 172 insertions(+) create mode 100644 pihole-cloudflared-DoH/.env create mode 100644 pihole-cloudflared-DoH/README.md create mode 100644 pihole-cloudflared-DoH/docker-compose.yaml diff --git a/README.md b/README.md index e3a465b..a6a609f 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ application with Nginx proxy and a Mongo database. application with an Nginx proxy and a MySQL database. - [`NGINX / Go`](https://github.com/docker/awesome-compose/tree/master/nginx-golang) - Sample Nginx proxy with a Go backend. - [`NGINX / WSGI / Flask`](https://github.com/docker/awesome-compose/tree/master/nginx-wsgi-flask) - Sample Nginx reverse proxy with a Flask backend using WSGI. +- [`Pi-hole / cloudflared`](https://github.com/docker/awesome-compose/tree/master/pihole-cloudflared-DoH) - Sample Pi-hole setup with use of DoH cloudflared service - [`React / Spring / MySQL`](https://github.com/docker/awesome-compose/tree/master/react-java-mysql) - Sample React application with a Spring backend and a MySQL database. - [`React / Express / MySQL`](https://github.com/docker/awesome-compose/tree/master/react-express-mysql) - Sample React diff --git a/pihole-cloudflared-DoH/.env b/pihole-cloudflared-DoH/.env new file mode 100644 index 0000000..e38d377 --- /dev/null +++ b/pihole-cloudflared-DoH/.env @@ -0,0 +1,8 @@ +TIMEZONE=Etc/UTC +PIHOLE_PW=changeit +# Default values for CONDITIONAL_FORWARDING with AVM FRITZ!Box +PIHOLE_ROUTER_IP=192.168.178.1 +PIHOLE_NETWORK_DOMAIN=fritz.box +PIHOLE_REVERSE_DNS=192.168.178.0/24 +PIHOLE_HOST_IP=192.168.178.X +PIHOLE_HOST_IPV6= diff --git a/pihole-cloudflared-DoH/README.md b/pihole-cloudflared-DoH/README.md new file mode 100644 index 0000000..b555598 --- /dev/null +++ b/pihole-cloudflared-DoH/README.md @@ -0,0 +1,108 @@ +## Pi-hole with cloudflared DoH (DNS-Over-HTTPS) +This example provides a base setup for using [Pi-hole](https://docs.pi-hole.net/) with the [cloudflared DoH](https://docs.pi-hole.net/guides/dns/cloudflared/) service. +More details on how to customize the installation and the compose file can be found in [Docker Pi-hole documentation](https://github.com/pi-hole/docker-pi-hole). + + +Project structure: +``` +. +├── .env +├── docker-compose.yaml +└── README.md +``` + +[_docker-compose.yaml_](docker-compose.yaml) +``` yaml +services: + pihole: + image: pihole/pihole:latest + ports: + - "53:53/tcp" + - "53:53/udp" + - "67:67/udp" + - "8080:80/tcp" + - "8443:443/tcp" + ... + cloudflared: + image: visibilityspots/cloudflared + ports: + - "5054:5054/tcp" + - "5054:5054/udp" + ... +``` + +## Configuration + +### .env +Before deploying this setup, you need to configure the following values in the [.env](.env) file. +- TZ ([time zone](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)) +- PIHOLE_PW (admin password) +- PIHOLE_ROUTER_IP (only needed for activated conditional forwarding) +- PIHOLE_NETWORK_DOMAIN (only needed for activated conditional forwarding) +- PIHOLE_HOST_IP (IPv4 address of your Pi-hole - needs to by static) +- PIHOLE_HOST_IPV6 (IPv6 address of your Pi-hole - can be empty if you only use IPv4) + +### Conditional forwarding (optional, default: enabled) +If you would like to disable conditional forwarding, delete the environment variables starting with "CONDITIONAL_FORWARDING" + +### Container DNS (optional, default: disabled) +In the docker-compose file, dns is added as a comment. To enable dns remove '#' in front of the following lines: +``` yaml +dns: + - 127.0.0.1 # "Sets your container's resolve settings to localhost so it can resolve DHCP hostnames [...]" - github.com/pi-hole/docker-pi-hole + - 1.1.1.1 # Backup server +``` + +## Deploy with docker-compose +When deploying this setup, the admin web interface will be available on port 8080 (e.g. http://localhost:8080/admin). + +``` shell +$ docker-compose up -d +Starting cloudflared ... done +Starting pihole ... done +``` + + +## Expected result + +Check containers are running and the port mapping: +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +afcf5ca4214c pihole/pihole:latest "/s6-init" 3 seconds ago Up 3 seconds (health: starting) 0.0.0.0:53->53/udp, 0.0.0.0:53->53/tcp, 0.0.0.0:67->67/udp, 0.0.0.0:8080->80/tcp, 0.0.0.0:8443->443/tcp pihole +dfd49ab7a372 visibilityspots/cloudflared "/bin/sh -c '/usr/lo…" 4 seconds ago Up 3 seconds (health: starting) 0.0.0.0:5054->5054/tcp, 0.0.0.0:5054->5054/udp cloudflared +``` + +Navigate to `http://localhost:8080` in your web browser to access the installed Pi-hole web interface. + + +Stop the containers with +``` shell +$ docker-compose down +# To delete all data run: +$ docker-compose down -v +``` + +## Troubleshooting + +### - Starting / Stopping pihole-FTL loop: + Sometimes, it can happen that there occurs a problem starting pihole-FTL. + I personally had this issue when adding this line to the shared volumes: + ``` + - "/pihole/pihole.log:/var/log/pihole.log" + ``` + To fix this issue, I found this [issue](https://github.com/pi-hole/docker-pi-hole/issues/645#issuecomment-670809672), + which suggested adding an empty file (`touch /pihole/pihole.log`) to prevent it from creating a directory. + The directory would not allow starting pihole-FTL and result in something like this: + ``` + # Starting pihole-FTL (no-daemon) as root + # Stopping pihole-FTL + ... + ``` + If you created an empty file, you may also check the ownership to prevent permission problems. + +### - Installing on Ubuntu may conflict with `systemd-resolved` - see [Installing on Ubuntu](https://github.com/pi-hole/docker-pi-hole#installing-on-ubuntu) for help. + +### - Environment variables are version-dependent + Environment variables like "CONDIIONAL_FORWARDING*" and "DNS1" are deprecated and replaced by e.g. "REV_SERVER*" and "PIHOLE_DNS" in version 5.8+. + Current information about environment variables can be found here: https://github.com/pi-hole/docker-pi-hole \ No newline at end of file diff --git a/pihole-cloudflared-DoH/docker-compose.yaml b/pihole-cloudflared-DoH/docker-compose.yaml new file mode 100644 index 0000000..0ab776f --- /dev/null +++ b/pihole-cloudflared-DoH/docker-compose.yaml @@ -0,0 +1,55 @@ +version: '3.7' +services: + cloudflared: + image: visibilityspots/cloudflared + container_name: cloudflared + ports: + - "5054:5054/tcp" + - "5054:5054/udp" + environment: + - TZ=${TIMEZONE} + - PORT=5054 + - ADDRESS=0.0.0.0 + restart: always + networks: + dns-net: + ipv4_address: 172.20.0.2 + + pihole: + container_name: pihole + image: pihole/pihole:latest + ports: + - "53:53/tcp" + - "53:53/udp" + - "67:67/udp" + - "8080:80/tcp" + - "8443:443/tcp" + environment: + - TZ=${TIMEZONE} + - PIHOLE_DNS_=172.20.0.2#5054;1.1.1.1 # referencing by name results in "Invalid IP detected in PIHOLE_DNS_: cloudflared#5054" + - WEBPASSWORD=${PIHOLE_PW} + - REV_SERVER=true + - REV_SERVER_TARGET=${PIHOLE_ROUTER_IP} + - REV_SERVER_DOMAIN=${PIHOLE_NETWORK_DOMAIN} + - REV_SERVER_CIDR=${PIHOLE_REVERSE_DNS} + - ServerIP=${PIHOLE_HOST_IP} + - ServerIPv6=${PIHOLE_HOST_IPV6} + #dns: + #- 127.0.0.1 # "Sets your container's resolve settings to localhost so it can resolve DHCP hostnames [...]" - github.com/pi-hole/docker-pi-hole + #- 1.1.1.1 # Backup server + volumes: # store your data between container upgrades + - "/etc/pihole/:/etc/pihole/" + - "/etc/dnsmasq.d/:/etc/dnsmasq.d/" + cap_add: + - NET_ADMIN # Recommended but not required (DHCP needs NET_ADMIN) https://github.com/pi-hole/docker-pi-hole#note-on-capabilities + depends_on: + - "cloudflared" + restart: always + networks: + - dns-net + +networks: + dns-net: + ipam: + config: + - subnet: 172.20.0.0/24 \ No newline at end of file From 800e211fc46af6b03a2833f31fc99f0fd199d67e Mon Sep 17 00:00:00 2001 From: Leon Stoldt Date: Sat, 7 Aug 2021 14:36:28 +0200 Subject: [PATCH 2/5] Adding Plex example Signed-off-by: Leon Stoldt --- README.md | 1 + plex/.env | 1 + plex/README.md | 57 ++++++++++++++++++++++++++++++++++++++++ plex/docker-compose.yaml | 11 ++++++++ 4 files changed, 70 insertions(+) create mode 100644 plex/.env create mode 100644 plex/README.md create mode 100644 plex/docker-compose.yaml diff --git a/README.md b/README.md index a6a609f..4275f17 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ with Spring framework and a Postgres database. - [`Traefik`](https://github.com/docker/awesome-compose/tree/master/traefik-golang) - [`Django`](https://github.com/docker/awesome-compose/tree/master/django) - [`Minecraft server`](https://github.com/docker/awesome-compose/tree/master/minecraft) +- [`Plex`](https://github.com/docker/awesome-compose/tree/master/plex) ## Basic setups for different platforms (not production ready - useful for personal use) - [`Gitea / PostgreSQL`](https://github.com/docker/awesome-compose/tree/master/gitea-postgres) - [`Nextcloud / PostgreSQL`](https://github.com/docker/awesome-compose/tree/master/nextcloud-postgres) diff --git a/plex/.env b/plex/.env new file mode 100644 index 0000000..5154992 --- /dev/null +++ b/plex/.env @@ -0,0 +1 @@ +PLEX_MEDIA_PATH=/media/your/plex/path diff --git a/plex/README.md b/plex/README.md new file mode 100644 index 0000000..0839ee2 --- /dev/null +++ b/plex/README.md @@ -0,0 +1,57 @@ +## Plex +This example provides a base setup for using [Plex](https://www.plex.tv/). +More details on how to customize the installation and the compose file can be found in [linuxserver documentation](https://github.com/linuxserver/docker-plex). +Alternatively, you can use different plex images (e.g. official plex image by [plexinc](https://github.com/plexinc/pms-docker)) + + +Project structure: +``` +. +├── .env +├── docker-compose.yaml +└── README.md +``` + +[_docker-compose.yaml_](docker-compose.yaml) +``` yaml +services: + plex: + image: linuxserver/plex:latest +``` + +## Configuration + +### .env +Before deploying this setup, you need to configure the following values in the [.env](.env) file. +- PLEX_MEDIA_PATH + +### Hardware Acceleration +Check out the description for Hardware Acceleration support in the [documentation](https://github.com/linuxserver/docker-plex). + +## Deploy with docker-compose +When deploying this setup, the web interface will be available on port 32400 (e.g. http://localhost:32400/web). + +``` shell +$ docker-compose up -d +Starting plex ... done +``` + + +## Expected result + +Check containers are running: +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +62fc3ff1f1a0 ghcr.io/linuxserver/plex:latest "/init" 38 seconds ago Up 3 seconds plex +``` + +Navigate to `http://localhost:32400/web` in your web browser to access the plex web interface. + + +Stop the containers with +``` shell +$ docker-compose down +# To delete all data run: +$ docker-compose down -v +``` diff --git a/plex/docker-compose.yaml b/plex/docker-compose.yaml new file mode 100644 index 0000000..f628583 --- /dev/null +++ b/plex/docker-compose.yaml @@ -0,0 +1,11 @@ +version: '3.7' +services: + plex: + image: ghcr.io/linuxserver/plex:latest + container_name: plex + network_mode: host + environment: + - VERSION=docker + restart: always + volumes: + - ${PLEX_MEDIA_PATH}:/media/ \ No newline at end of file From 5cfa856a07e6853dbf0754bf777e9d84e3f79bd1 Mon Sep 17 00:00:00 2001 From: Leon Stoldt Date: Sat, 7 Aug 2021 14:37:23 +0200 Subject: [PATCH 3/5] Adding portainer example Signed-off-by: Leon Stoldt --- README.md | 1 + portainer/README.md | 56 +++++++++++++++++++++++++++++++++++ portainer/docker-compose.yaml | 15 ++++++++++ 3 files changed, 72 insertions(+) create mode 100644 portainer/README.md create mode 100644 portainer/docker-compose.yaml diff --git a/README.md b/README.md index 4275f17..a5f4d45 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ with Spring framework and a Postgres database. - [`Django`](https://github.com/docker/awesome-compose/tree/master/django) - [`Minecraft server`](https://github.com/docker/awesome-compose/tree/master/minecraft) - [`Plex`](https://github.com/docker/awesome-compose/tree/master/plex) +- [`Portainer`](https://github.com/docker/awesome-compose/tree/master/portainer) ## Basic setups for different platforms (not production ready - useful for personal use) - [`Gitea / PostgreSQL`](https://github.com/docker/awesome-compose/tree/master/gitea-postgres) - [`Nextcloud / PostgreSQL`](https://github.com/docker/awesome-compose/tree/master/nextcloud-postgres) diff --git a/portainer/README.md b/portainer/README.md new file mode 100644 index 0000000..6c2e948 --- /dev/null +++ b/portainer/README.md @@ -0,0 +1,56 @@ +## Portainer (CE) +This example provides a base setup for using [Portainer](https://www.portainer.io/). +More details on how to customize the installation and the compose file can be found in [portainer documentation](https://documentation.portainer.io/). + +### Demo +You can try out the public demo instance first: http://demo.portainer.io/ +- username: admin +- password: tryportainer + +Project structure: +``` +. +├── docker-compose.yaml +└── README.md +``` + +[_docker-compose.yaml_](docker-compose.yaml) +``` yaml +services: + portainer: + image: portainer/portainer-ce:alpine +``` + +## Deploy with docker-compose +When deploying this setup, the web interface will be available on port 9000 (e.g. http://localhost:9000). + +``` shell +$ docker-compose up -d +Starting portainer ... done +``` + + +## Expected result + +Check containers are running: +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +860311c00e62 portainer/portainer-ce:alpine "/portainer -H unix:…" 54 seconds ago Up 53 seconds 8000/tcp, 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp portainer + +``` + +Navigate to `http://localhost:9000` in your web browser to access the portainer web interface and create an account. + + +Stop the containers with +``` shell +$ docker-compose down +# To delete all data run: +$ docker-compose down -v +``` + +## Troubleshooting +- Select the correct image for your OS. You can take a look at the published tags at [DockerHub](https://hub.docker.com/r/portainer/portainer-ce/tags) + +> e.g. currently, the latest tag is for Windows (amd64) and alpine for Linux (amd64, arm/v7) \ No newline at end of file diff --git a/portainer/docker-compose.yaml b/portainer/docker-compose.yaml new file mode 100644 index 0000000..56c3e6b --- /dev/null +++ b/portainer/docker-compose.yaml @@ -0,0 +1,15 @@ +version: '3.7' +services: + portainer: + image: portainer/portainer-ce:alpine + container_name: portainer + command: -H unix:///var/run/docker.sock + ports: + - "9000:9000" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "portainer_data:/data" + restart: always + +volumes: + portainer_data: \ No newline at end of file From acf94458dcae262016763b89d10392666daaed84 Mon Sep 17 00:00:00 2001 From: Leon Stoldt Date: Sat, 7 Aug 2021 14:38:20 +0200 Subject: [PATCH 4/5] Adding wireguard example Signed-off-by: Leon Stoldt --- README.md | 1 + wireguard/.env | 2 + wireguard/README.md | 78 +++++++++++++++++++++++++++++++++++ wireguard/docker-compose.yaml | 27 ++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 wireguard/.env create mode 100644 wireguard/README.md create mode 100644 wireguard/docker-compose.yaml diff --git a/README.md b/README.md index a5f4d45..bb38859 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ with Spring framework and a Postgres database. - [`Minecraft server`](https://github.com/docker/awesome-compose/tree/master/minecraft) - [`Plex`](https://github.com/docker/awesome-compose/tree/master/plex) - [`Portainer`](https://github.com/docker/awesome-compose/tree/master/portainer) +- [`Wireguard`](https://github.com/docker/awesome-compose/tree/master/wireguard) ## Basic setups for different platforms (not production ready - useful for personal use) - [`Gitea / PostgreSQL`](https://github.com/docker/awesome-compose/tree/master/gitea-postgres) - [`Nextcloud / PostgreSQL`](https://github.com/docker/awesome-compose/tree/master/nextcloud-postgres) diff --git a/wireguard/.env b/wireguard/.env new file mode 100644 index 0000000..02e23d8 --- /dev/null +++ b/wireguard/.env @@ -0,0 +1,2 @@ +TIMEZONE=Etc/UTC +VPN_SERVER_URL=your-domain.dyndns.com # free examples http://www.duckdns.org/ and https://www.noip.com/ \ No newline at end of file diff --git a/wireguard/README.md b/wireguard/README.md new file mode 100644 index 0000000..ab6f8b5 --- /dev/null +++ b/wireguard/README.md @@ -0,0 +1,78 @@ +## Wireguard +This example provides a base setup for using [Wireguard](https://www.wireguard.com/). +More details on how to customize the installation and the compose file can be found in [linuxserver documentation](https://hub.docker.com/r/linuxserver/wireguard). + +Project structure: +``` +. +├── .env +├── docker-compose.yaml +└── README.md +``` + +[_docker-compose.yaml_](docker-compose.yaml) +``` yaml +services: + wireguard: + image: ghcr.io/linuxserver/wireguard +``` + +## Configuration + +### .env +Before deploying this setup, you need to configure the following values in the [.env](.env) file. +- TIMEZONE +- VPN_SERVER_URL (recommended setting up a server url with e.g. http://www.duckdns.org/ if you don't own a domain) + +## Deploy with docker-compose +When deploying this setup, the log will show relevant information. You need to forward the external port 51820 to access your VPN from outside. + +``` shell +$ docker-compose up +Starting wireguard ... +wireguard | **** It seems the wireguard module is already active. Skipping kernel header install and module compilation. **** +wireguard | **** Server mode is selected **** +wireguard | **** External server address is set to your-domain.dyndns.com # free examples http://www.duckdns.org/ and https://www.noip.com/ **** +wireguard | **** External server port is set to 51820. Make sure that port is properly forwarded to port 51820 inside this container **** +[...] +wireguard | PEER 1 QR code: +wireguard | [GENERATED QR CODE TO SCAN FOR YOUR CONNECTION DETAILS] + +``` + +## Expected result + +Check containers are running: +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +4992922d23dc ghcr.io/linuxserver/wireguard "/init" 7 seconds ago Up 5 seconds 0.0.0.0:51820->51820/udp, :::51820->51820/udp wireguard +``` + +## Mobile Wireguard App + +### Android + + +Install your Wireguard client on an Apple device by downloading the wireguard app and scanning the QR Code. + +### iOS + + +Install your Wireguard client on an Apple device by downloading the wireguard app and scanning the QR Code. + +Stop the containers with +``` shell +$ docker-compose down +# To delete all data run: +$ docker-compose down -v +``` + +## Troubleshooting + +### - (Raspberry Pi) Kernel Headers + On Raspberry Pi run `sudo apt update && sudo apt upgrade && sudo apt install raspberrypi-kernel-headers` and reboot before starting Wireguard. + Other Ubuntu / Debian based systems may need to install the kernel-headers too. Run `sudo apt update && sudo apt upgrade && sudo apt install linux-headers-$(uname -r)` + +### - Server Mode Options + To create new clients or display existing ones, take a look at the "[Server Mode](https://hub.docker.com/r/linuxserver/wireguard)" section \ No newline at end of file diff --git a/wireguard/docker-compose.yaml b/wireguard/docker-compose.yaml new file mode 100644 index 0000000..8871150 --- /dev/null +++ b/wireguard/docker-compose.yaml @@ -0,0 +1,27 @@ +version: '3.7' +services: + wireguard: + image: ghcr.io/linuxserver/wireguard + container_name: wireguard + cap_add: + - NET_ADMIN + - SYS_MODULE + environment: + - PUID=1000 + - PGID=1000 + - TZ=${ZIMEZONE} + - SERVERURL=${VPN_SERVER_URL} #optional + - SERVERPORT=51820 #optional + - PEERS=1 #optional + - PEERDNS=auto #optional + - INTERNAL_SUBNET=10.13.13.0 #optional + - ALLOWEDIPS=0.0.0.0/0 #optional + volumes: + - /usr/share/appdata/wireguard/config:/config + - /usr/src:/usr/src # location of kernel headers + - /lib/modules:/lib/modules + ports: + - 51820:51820/udp + sysctls: + - net.ipv4.conf.all.src_valid_mark=1 + restart: unless-stopped \ No newline at end of file From 1fd4ba878dcafc9706228bbc4beeb4f296c9729e Mon Sep 17 00:00:00 2001 From: Leon Stoldt Date: Sat, 7 Aug 2021 14:39:17 +0200 Subject: [PATCH 5/5] Adding postgreSQL / pgAdmin example Signed-off-by: Leon Stoldt --- README.md | 1 + postgresql-pgadmin/.env | 5 ++ postgresql-pgadmin/README.md | 68 ++++++++++++++++++++++++++ postgresql-pgadmin/docker-compose.yaml | 22 +++++++++ 4 files changed, 96 insertions(+) create mode 100644 postgresql-pgadmin/.env create mode 100644 postgresql-pgadmin/README.md create mode 100644 postgresql-pgadmin/docker-compose.yaml diff --git a/README.md b/README.md index bb38859..69f39f9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ application with an Nginx proxy and a MySQL database. - [`NGINX / Go`](https://github.com/docker/awesome-compose/tree/master/nginx-golang) - Sample Nginx proxy with a Go backend. - [`NGINX / WSGI / Flask`](https://github.com/docker/awesome-compose/tree/master/nginx-wsgi-flask) - Sample Nginx reverse proxy with a Flask backend using WSGI. - [`Pi-hole / cloudflared`](https://github.com/docker/awesome-compose/tree/master/pihole-cloudflared-DoH) - Sample Pi-hole setup with use of DoH cloudflared service +- [`PostgreSQL / pgAdmin`](https://github.com/docker/awesome-compose/tree/master/postgresql-pgadmin) - Sample setup for postgreSQL database with pgAdmin web interface - [`React / Spring / MySQL`](https://github.com/docker/awesome-compose/tree/master/react-java-mysql) - Sample React application with a Spring backend and a MySQL database. - [`React / Express / MySQL`](https://github.com/docker/awesome-compose/tree/master/react-express-mysql) - Sample React diff --git a/postgresql-pgadmin/.env b/postgresql-pgadmin/.env new file mode 100644 index 0000000..961e9ab --- /dev/null +++ b/postgresql-pgadmin/.env @@ -0,0 +1,5 @@ +POSTGRES_USER=yourUser +POSTGRES_PW=changeit +POSTGRES_DB=postgres +PGADMIN_MAIL=your@email.com +PGADMIN_PW=changeit \ No newline at end of file diff --git a/postgresql-pgadmin/README.md b/postgresql-pgadmin/README.md new file mode 100644 index 0000000..6a5379a --- /dev/null +++ b/postgresql-pgadmin/README.md @@ -0,0 +1,68 @@ +## PostgreSQL and pgAdmin +This example provides a base setup for using [PostgreSQL](https://www.postgresql.org/) and [pgAdmin](https://www.pgadmin.org/). +More details on how to customize the installation and the compose file can be found [here (PostgreSQL)](https://hub.docker.com/_/postgres) and [here (pgAdmin)](https://www.pgadmin.org/docs/pgadmin4/latest/container_deployment.html). + +Project structure: +``` +. +├── .env +├── docker-compose.yaml +└── README.md +``` + +[_docker-compose.yaml_](docker-compose.yaml) +``` yaml +services: + postgres: + image: postgres:latest + ... + pgadmin: + image: dpage/pgadmin4:latest +``` + +## Configuration + +### .env +Before deploying this setup, you need to configure the following values in the [.env](.env) file. +- POSTGRES_USER +- POSTGRES_PW +- POSTGRES_DB (can be default value) +- PGADMIN_MAIL +- PGADMIN_PW + +## Deploy with docker-compose +When deploying this setup, the pgAdmin web interface will be available at port 5050 (e.g. http://localhost:5050). + +``` shell +$ docker-compose up +Starting postgres ... done +Starting pgadmin ... done +``` + +## Add postgres database to pgAdmin +After logging in with your credentials of the .env file, you can add your database to pgAdmin. +1. Right-click "Servers" in the top-left corner and select "Create" -> "Server..." +2. Name your connection +3. Change to the "Connection" tab and add the connection details: +- Hostname: "postgres" (this would normally be your IP address of the postgres database - however, docker can resolve this container ip by its name) +- Port: "5432" +- Maintenance Database: $POSTGRES_DB (see .env) +- Username: $POSTGRES_USER (see .env) +- Password: $POSTGRES_PW (see .env) + +## Expected result + +Check containers are running: +``` +$ docker ps +CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES +849c5f48f784 postgres:latest "docker-entrypoint.s…" 9 minutes ago Up 9 minutes 0.0.0.0:5432->5432/tcp, :::5432->5432/tcp postgres +d3cde3b455ee dpage/pgadmin4:latest "/entrypoint.sh" 9 minutes ago Up 9 minutes 443/tcp, 0.0.0.0:5050->80/tcp, :::5050->80/tcp pgadmin +``` + +Stop the containers with +``` shell +$ docker-compose down +# To delete all data run: +$ docker-compose down -v +``` diff --git a/postgresql-pgadmin/docker-compose.yaml b/postgresql-pgadmin/docker-compose.yaml new file mode 100644 index 0000000..f7ed714 --- /dev/null +++ b/postgresql-pgadmin/docker-compose.yaml @@ -0,0 +1,22 @@ +version: '3.7' +services: + postgres: + container_name: postgres + image: postgres:latest + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PW} + - POSTGRES_DB=${POSTGRES_DB} #optional (specify default database instead of $POSTGRES_USER) + ports: + - "5432:5432" + restart: always + + pgadmin: + container_name: pgadmin + image: dpage/pgadmin4:latest + environment: + - PGADMIN_DEFAULT_EMAIL=${PGADMIN_MAIL} + - PGADMIN_DEFAULT_PASSWORD=${PGADMIN_PW} + ports: + - "5050:80" + restart: always