yaml for pihole container on QNAP - docker-compose

I am trying to make the following docker-compose.yaml to run on my QNAP container station.
The following part is working, but after the "restart: unless-stopped" the mess begins.
version: '3'
services:
pihole:
container_name: pihole
image: pihole/pihole:latest
ports:
- "65003:53/tcp"
- "65002:53/udp"
- "65001:67/udp"
- "65000:80/tcp"
environment:
TZ: 'Berlin'
WEBPASSWORD: 'password'
# Volumes store your data between container upgrades
volumes:
- './etc-pihole/:/etc/pihole/'
- './etc-dnsmasq.d/:/etc/dnsmasq.d/'
# Recommended but not required (DHCP needs NET_ADMIN)
# https://github.com/pi-hole/docker-pi-hole#note-on-capabilities
cap_add:
- NET_ADMIN
restart: unless-stopped
qnet_dhcp:
image: alpine
command: ifconfig eth0
networks:
- qnet-dhcp
qnet_static:
image: alpine
command: ifconfig eth0
networks:
qnet-static:
ipv4_address: 192.168.178.2
networks:
qnet-dhcp:
driver: qnet
ipam:
driver: qnet
options:
iface: "eth0"
qnet-static:
driver: qnet
ipam:
driver: qnet
options:
iface: "eth0"
config:
- subnet: 192.168.178.0/24
gateway: 192.168.178.1
I got the network information directly from QNAP https://qnap-dev.github.io/container-station-api/qnet.html and tried to verify it with http://www.yamllint.com/, but it does not work together.
error
line 24
notvalid

One of your service names is not correctly indented.
Additionally, you have provided an invalid configuration for ipam for the version 3 file. You can only provide options in version 2 according to the docs.
I will truncate the file for brevity.
# you need file version 2 in order to use options in ipam
# the file you copied it from is also using version 2
version: '2'
services:
pihole:
...
# this one (qnet_dhcp) is the name of another service.
# In your original code the indention is incorrect.
# It should be aligned with the other services.
qnet_dhcp:
...
qnet_static:
...
networks:
qnet-dhcp:
...
ipam:
...
# as mentioned above,
# this is only valid in version 2
options:
...

Related

Docker-Compose | why the containers can't reach each other?

I have been trying to create a docker-compose file to get my web application up and running using only 'docker-compose up'. I can't make the containers reach each other, currently, I'm trying that the backend container connects to the postgres DB.
I have added a health check for the postgres container
I have been trying to add 'network_mode: host' to the postgres container but with no success.
I am using Prisma as an ORM to connect to the DB.
This is my docker-compose.yml file:
version: "2.1"
services:
##############################
# Database Container
##############################
postgres:
restart: always
container_name: db
hostname: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
ports:
- "5432:5432"
build:
dockerfile: ./database/Dockerfile
context: .
networks:
- mynet
healthcheck:
test: ["CMD-SHELL", "pg_isready -d postgres -U postgres"]
interval: 10s
timeout: 5s
retries: 5
# ##############################
# # Backend Container
# ##############################
backend:
restart: always
container_name: backend
hostname: backend
environment:
- DATABASE_URL=postgresql://postgres:postgres#localhost:5432/postgres?schema=public
build:
dockerfile: ./Dockerfile
context: ./backend
depends_on:
postgres:
condition: service_healthy
networks:
- mynet
ports:
- "3001:3000"
# ##############################
# # Frontend Container
# ##############################
# frontend:
# restart: always
# container_name: frontend
# hostname: frontend
# build:
# dockerfile: ./Dockerfile
# context: ./frontend
# ports:
# - "3000:3000"
# depends_on:
# - "backend"
networks:
mynet:
driver: bridge
That's what I am getting ( Currently trying to communicate between the backend and Postgres containers. ):
I really appreciate any help you can provide.
Just use the name of the database-service as hostname.
- DATABASE_URL=postgresql://postgres:postgres#postgres:5432/postgres?schema=public
edit
Docker containers are a little bit like a virtual machine. They have their own isolated network. When you write down the container ports (it is the ports-part of your docker-compose), then is docker able to establish a routing between your containers.
Docker container "A" can talk to container "B" with only knowing the port and the name of the container.
When you want to talk from your host to container, then you have to publish the ports. You already did it with 3001:3001.
That means for docker: All traffic on port 3001 on the host will be redirected to container on port 3001. <portOnHost>:<portOnContainer>
I recommend to learn something about the networking. Here is documentation of docker.

Using a docker container with a VPN

I'm kinda new to docker so maybe my question is stupid, however, I've been unable to find a solution for it for a while now and it's starting to bother me so I'm asking here:
I have a default bridge network inside which there are few containers, one of them is running gluetun which is a vpn client and the rest is what's known as apache guacamole which is used as a remote desktop gateway.
It looks something like this:
networks:
guacnetwork_compose:
driver: bridge
services:
#gluten
gluetun:
image: qmcgaw/gluetun
#trqbva da mu dadem net_admin inache openvpn ne raboti
cap_add:
- NET_ADMIN
ports:
- 8888:8888/tcp # HTTP proxy
- 8388:8388/tcp # Shadowsocks
- 8388:8388/udp # Shadowsocks
# - 4823:4822
# networks:
# enable_ipv6=false
volumes:
environment:
- VPNSP=custom
- VPN_TYPE=openvpn
# OpenVPN:
- OPENVPN_USER=
- OPENVPN_PASSWORD=
- OPENVPN_CUSTOM_CONFIG=
# Timezone for accurate log times
# - TZ=
#guacd
guacd:
container_name: guacd_compose
image: guacamole/guacd
network_mode: "service:gluetun"
# networks:
# guacnetwork_compose:
restart: always
volumes:
- ./drive:/drive:rw
- ./record:/record:rw
# ports:
# - 4823:4822
guacd-no-vpn:
container_name: guacd_compose_no_vpn
image: guacamole/guacd
networks:
- guacnetwork_compose
restart: always
volumes:
- ./drive:/drive:rw
- ./record:/record:rw
# guacamole
guacamole:
container_name: guacamole_compose
depends_on:
- guacd
- postgres
environment:
GUACD_HOSTNAME: guacd
POSTGRES_DATABASE:
POSTGRES_HOSTNAME:
POSTGRES_PASSWORD:
POSTGRES_USER:
image: guacamole/guacamole
links:
- gluetun
networks:
- guacnetwork_compose
ports:
## if not nginx
## - 8080:8080/tcp # Guacamole is on :8080/guacamole, not /.
- 8080/tcp
restart: always
Basically what I want to happen is for the guacd container to use the network of the VPN container and then communicate with the GUI which is the guacamole container. Currently, the guacd is using the gluetun network, however, I can not get it to communicate with the guacamole container despite my efforts. Could somebody tell me what am I doing wrong?

Run docker postrgessql image twice first exits

I made 2 yml and when i run docker-compose -f postgresql.yml up its starts ok
and then when i run docker-compose -f postgresql2.yml up first exist code 0.
Is it even possible to run same image twice?
My main purpose to run same web app source twice with different db on the same server pc.
1 web app source 2 instances with self db each on one server(maybe its clearer definition).
Maybe there is better approach and I do and think everything in wrong way.
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
version: '3.8'
services:
freshhipster-postgresql:
image: postgres:13.1
environment:
- POSTGRES_USER=FreshHipster
- POSTGRES_PASSWORD=
- POSTGRES_HOST_AUTH_METHOD=trust
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 5432:5432
and this no big difference
postgresql2.yml
# This configuration is intended for development purpose, it's **your** responsibility to harden it for production
version: '3.8'
services:
freshhipster-postgresql:
image: postgres:13.1
container_name: postgres2
volumes:
- pgdata:/var/lib/postgresql/data_vol2/
environment:
- POSTGRES_USER=FreshHipster
- POSTGRES_PASSWORD=
- POSTGRES_HOST_AUTH_METHOD=trust
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 5433:5432
volumes:
pgdata:
external: true
Just use another service name freshhipster-postgresql2 on postgresql2.yml
version: '3.8'
services:
freshhipster-postgresql2:
image: postgres:13.1
container_name: postgres2
volumes:
- pgdata:/var/lib/postgresql/data_vol2/
environment:
- POSTGRES_USER=FreshHipster
- POSTGRES_PASSWORD=
- POSTGRES_HOST_AUTH_METHOD=trust
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 5433:5432
volumes:
pgdata:
external: true

traefik v2.2 help using only docker-compose router service entrypoint

Started learning about docker, traefik for playing in home.
Aim: Put everything all together in docker-compose.yml and .env files, understand basics, comment accordingly.
Want to get dashboard from traefik.test.local/dashboard rather test.local:8080, similarly api should be accessed from traefik.test.local/api. So that don't have to think about port numbers.
added lines to /etc/hosts
127.0.0.1 test.local
127.0.0.1 traefik.test.local
docker-compose.yml
version: "3.7"
services:
traefik:
# The official v2 Traefik docker image
image: traefik:v2.2
# Lets name the container
container_name: traefik
command:
# Enables the web UI
- "--api.insecure=true"
# Tells Traefik to listen to docker
- "--providers.docker"
ports:
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
- "8080:8080"
volumes:
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
#labels:
#- "traefik.http.routers.router.rule=Host(`traefik.test.local/dashboard`)"
#- "traefik.http.routers.router.rule=Host(`traefik.test.local/api`)"
restart:
always
Not able to understand how to connect from router to services. Also correct me if I am wrong anywhere. Thank you.
PS: OS: kde-neon
you can achieve this using the following definition, you need to add labels for the routers and service and not only the router
proxy:
image: traefik:v2.1
command:
- '--providers.docker=true'
- '--entryPoints.web.address=:80'
- '--entryPoints.metrics.address=:8082'
- '--providers.providersThrottleDuration=2s'
- '--providers.docker.watch=true'
- '--providers.docker.swarmMode=true'
- '--providers.docker.swarmModeRefreshSeconds=15s'
- '--providers.docker.exposedbydefault=false'
- '--providers.docker.defaultRule=Host("traefik.lvh.me")'
- '--accessLog.bufferingSize=0'
- '--api=true'
- '--api.dashboard=true'
- '--api.insecure=true'
- '--ping.entryPoint=web'
volumes:
- '/var/run/docker.sock:/var/run/docker.sock:ro'
ports:
- '80:80'
- '8080:8080'
restart:
always
deploy:
labels:
- traefik.enable=true
- traefik.docker.network=monitoring
- traefik.http.services.traefik-dashboard.loadbalancer.server.port=8080
- traefik.http.routers.traefik-dashboard.rule=Host(`dashboard.traefik.lvh.me`)
- traefik.http.routers.traefik-dashboard.service=traefik-dashboard
- traefik.http.routers.traefik-dashboard.entrypoints=web
- traefik.http.services.traefik-api.loadbalancer.server.port=80
- traefik.http.routers.traefik-api.rule=Host(`api.traefik.lvh.me`)
- traefik.http.routers.traefik-api.service=traefik-api
- traefik.http.routers.traefik-api.entrypoints=web
logging:
driver: json-file
options:
'max-size': '10m'
'max-file': '5'
also if you use lvh.me domain you not need to edit /etc/hosts

How to restrict creating default network from docker-compose file

I have overlapping with default docker subnets, so I want to setup for some services custom network. docker-compose version:3
example of docker-compose.yml
version: '3'
services:
service1:
build:
dockerfile: Dockerfile
service2:
build:
dockerfile: Dockerfile1
service3:
build:
dockerfile: Dockerfile2
networks:
- net1
networks:
net1:
ipam:
driver: default
config:
- subnet: "172.101.0.0/24"
So when I execute the following command I got 2 networks :
docker-compose up --build -d service3
project_default and project_net1
But I need default network for other services so I can't change default settings.
What should I do to not create default network if it's not used for the service?
If you don't have a networks: specification for a given service, Docker Compose behaves as though you specified networks: [default]. In your example, service1 and service2 are on the default network and service3 is on the net1 network.
If you really need Docker Compose to not create the project_default network then you need to assign every container to some other network. From experimenting with a minimal docker-compose.yml file, explicitly adding networks: [net1] to the two services that don't already have it will cause the default network to not be created.
If your real issue is just around an IP address conflict, you're allowed to manually configure the default network and this might be easier.
version: '3'
services:
service1:
build: .
# with no networks:, so it gets the default
networks:
default:
ipam:
driver: default
config:
- subnet: "172.101.0.0/24"