docker-compose volumes settings - docker

version: '3.9'
services:
reverse-proxy:
image: nginxproxy/nginx-proxy:latest
container_name: reverse-proxy
restart: always
ports:
- 80:80
- 443:443
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs:ro
- /etc/nginx/bots.d:/etc/nginx/bots.d # for bad_bot ddos
- /var/run/docker.sock:/tmp/docker.sock:ro
- /var/log/nginx-proxy:/var/log/nginx
acme-companion:
image: nginxproxy/acme-companion:latest
depends_on:
- reverse-proxy
container_name: acme-companion
restart: always
environment:
NGINX_PROXY_CONTAINER: reverse-proxy
volumes:
- conf:/etc/nginx/conf.d
- vhost:/etc/nginx/vhost.d
- html:/usr/share/nginx/html
- certs:/etc/nginx/certs:rw
- acme:/etc/acme.sh
- /var/run/docker.sock:/var/run/docker.sock:ro
volumes:
conf:
driver: local
vhost:
driver: local
certs:
driver: local
acme:
driver: local
html:
driver: local
networks:
default:
name: my-network
the volume files will automaticly created at /var/lib/docker/volumes
volumes:
conf:
driver: local
vhost:
driver: local
certs:
driver: local
acme:
driver: local
html:
driver: local
I want to set the vlome files to be created in /etc/nginx.
After searching in stackoverflow, I tried to set the bind and type in the volumes below, but it didn't work well.
Isn't there an exact way?

Related

Docker Container ignores port 80

Since I use macvlan network configuration and give every container a different IP, I would like to access the services via port 80 and not the costum port. But this doesn't work for me.
Currently I created the following docker-compose file:
version: '3.3'
networks:
dockervlan:
external: true
volumes:
data:
services:
uptime-kuma:
image: louislam/uptime-kuma:latest
container_name: uptime-kuma
volumes:
- data:/app/data
ports:
- "80:3001" # <Host Port>:<Container Port>
restart: unless-stopped
networks:
dockervlan:
ipv4_address: 192.168.178.194
After that I still be able to access the service via http://192.168.178.194:3001 but not via http://192.168.178.194
Same for portainer:
version: '3'
services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
ports:
- 80:9000
- 8000:8000
security_opt:
- no-new-privileges:true
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock
- data:/data
restart: unless-stopped
networks:
dockervlan:
ipv4_address: 192.168.178.200
networks:
dockervlan:
name: dockervlan
driver: macvlan
driver_opts:
parent: eth0
ipam:
config:
- subnet: "192.168.178.0/24"
ip_range: "192.168.178.192/26"
gateway: "192.168.178.1"
volumes:
data:
I also tried 3001:80 and 9000:80, which of course didn't work euther.
Where is my mistake?

Docker Jwilder nginx-proxy custom nginx configuration, proxy-wide basis by mounting in custom configuration volume

I'm testing Jwilder nginx-proxy custom nginx configuration using this command:
version: "3.8"
services:
reverse-proxy:
image: "jwilder/nginx-proxy:latest"
container_name: "reverse-proxy"
volumes:
- "html:/usr/share/nginx/html"
- "dhparam:/etc/nginx/dhparam"
- "vhost:/etc/nginx/vhost.d"
- "certs:/etc/nginx/certs"
- "/run/docker.sock:/tmp/docker.sock:ro"
- "PATH_TO/conf/myconf.conf:/etc/nginx/conf.d/myconf.conf:ro"
restart: "always"
networks:
- "net"
ports:
- "80:80"
- "443:443"
letsencrypt:
image: "jrcs/letsencrypt-nginx-proxy-companion:latest"
container_name: "letsencrypt-helper"
volumes:
- "html:/usr/share/nginx/html"
- "dhparam:/etc/nginx/dhparam"
- "vhost:/etc/nginx/vhost.d"
- "certs:/etc/nginx/certs"
- "/run/docker.sock:/var/run/docker.sock:ro"
environment:
NGINX_PROXY_CONTAINER: "reverse-proxy"
DEFAULT_EMAIL: "user#domain.com"
restart: "always"
depends_on:
- "reverse-proxy"
networks:
- "net"
volumes:
certs:
html:
vhost:
dhparam:
networks:
net:
external: true
this part doesn't seem to work
"PATH_TO/conf/myconf.conf:/etc/nginx/conf.d/myconf.conf:ro"
I have this error
nginx: [emerg] open() "/etc/nginx/security-headers-ssl.conf"
failed (2: No such file or directory) in /etc/nginx/conf.d/myconf.conf:34
I also tried adding custom config directly via the below, but it also didn't work.
docker cp PATH_TO/conf/myconf.conf reverse-proxy:/etc/nginx/conf.d/

Cannot curl/ping to the host ip from inside docker container

I used docker and have nginx as a reverse proxy with just 80 and 443 ports exposed on host machine. I also have other containers and nginx under same network with bridge driver. The problem is I am unable to curl/ping host machine IP from inside docker container. I can access other containers with local DNS though. Please help.
DOCKER-COMPOSE FILE
version: "3"
services:
mongo:
image: mongo
container_name: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=rootmongo
- MONGO_INITDB_ROOT_PASSWORD=p4Ss#1234#
# For Persistance
volumes:
- db_data:/data/db
- db_backup:/backup
- db_dump:/dump
restart: always
networks:
- app-network
wealth_advisor_admin:
build:
context: ./adminpanel
dockerfile: Dockerfile
image: wealth_advisor_admin
depends_on:
- mongo
restart: unless-stopped
container_name: wealth_advisor_admin
networks:
- app-network
wealth_advisor_web:
build:
context: .
dockerfile: Dockerfile
image: wealth_advisor_web
container_name: wealth_advisor_web
restart: unless-stopped
depends_on:
- mongo
networks:
- app-network
webserver:
image: nginx:mainline-alpine
container_name: webserver
restart: unless-stopped
ports:
- "80:80"
- "443:443"
volumes:
- web-root:/var/www/html
- ./nginx-conf:/etc/nginx/conf.d
- certbot-etc:/etc/letsencrypt
- certbot-var:/var/lib/letsencrypt
- dhparam:/etc/ssl/certs
depends_on:
- wealth_advisor_web
- wealth_advisor_admin
networks:
- app-network
certbot:
image: certbot/certbot
container_name: certbot
volumes:
- certbot-etc:/etc/letsencrypt
- certbot-var:/var/lib/letsencrypt
- web-root:/var/www/html
depends_on:
- wealth_advisor_web
command: ---------------
volumes:
certbot-etc:
web-root:
certbot-var:
db_data:
db_backup:
db_dump:
dhparam:
driver: local
driver_opts:
type: none
device: /root/trade/dhparam/
o: bind
networks:
app-network:
driver: bridge

Docker container host does not resolve when I am not connected to internet

I am unable to access my php container either by host name or ip address when I am not connected to internet. However, as soon as I connect to internet I can access container through ip or host name. I am on linux debian stretch.
/etc/hosts
127.0.0.1 test.dkr
docker-compose.yml
version: '3.2'
services:
web:
container_name: lamp_web
build:
context: .
dockerfile: ./images/php/Dockerfile
image: lamp-php-apache:7.2
ports:
- "80:80"
- "443:443"
volumes:
- ./www/lamp:/var/www/
- ./configs/php/lamp.ini:/usr/local/etc/php/lamp
- ./logs/apache:/var/log/apache2/lamp
tty: true
stdin_open: true
links:
- database:mysql
environment:
- APACHE_SERVERADMIN=admin#localhost
- APACHE_RUN_USER=www-data
- APACHE_RUN_GROUP=www-data
- APACHE_LOG_DIR=/var/log/apache2
- APACHE_PID_FILE=/var/run/apache2.pid
- APACHE_RUN_DIR=/var/run/apache2
- APACHE_LOCK_DIR=/var/lock/apache2
- XDEBUG_CONFIG=remote_host=host.docker.internal remote_port=9000 remote_enable=1
networks:
lamp:
ipv4_address: 172.19.0.3
database:
container_name: lamp_mysql
build:
context: .
dockerfile: ./images/mysql/Dockerfile
image: lamp-mysql:5.7
ports:
- "3306:3306"
volumes:
- ./data/mysql:/var/lib/mysql
networks:
- lamp
networks:
lamp:
driver: bridge
ipam:
driver: default
config:
- subnet: 172.19.0.0/24

Set specify IP for a Docker container from docker-compose.yml

I have the docker-compose.yml file
web_server:
build: web_server/
ports:
- "8000:8000"
links:
- mongo
tty: true
environment:
SYMFONY__MONGO_ADDRESS: mongo
SYMFONY__MONGO_PORT: 27017
networks:
app_net:
ipv4_address: 172.16.238.10
ipv6_address: 2001:3984:3989::10
networks:
app_net:
driver: bridge
enable_ipv6: true
ipam:
driver: default
config:
-
subnet: 172.16.238.0/24
-
subnet: 2001:3984:3989::/64
mongo:
image: mongo:3.0
container_name: mongo
command: mongod --smallfiles
expose:
- 27017
I want to have a specifiy IP for my web_server for pass this in another applications.
But when I call command docker-compose up I recive the error:
ERROR: The Compose file '.\docker-compose.yml' is invalid because:
Unsupported config option for networks: 'app_net'
Unsupported config option for web_server: 'networks'
What is wrong?
I dont't known why you have this error but you can try to fix some points:
webserver networks must refer the networks declared below
you simplify your network configuration and start with ipv4 only
Here is a working configuration:
version: '2'
services:
webssl:
image: nginx:1.11.4-alpine
ports:
- "443:443"
- "80:80"
volumes:
- /data/nginx/webroot:/usr/share/nginx/html:ro
networks:
- dmz
networks:
dmz:
ipam:
driver: default
config:
- subnet: 172.77.0.1/24
ip_range: 172.77.0.0/24
gateway: 172.77.0.1

Resources