Ever since I specified a defined bridge network to my docker-compose file my server refuses to curl with localhost. I’ve tried a number of options but just cannot seem to make it work.
Astonishingly enough the phpadmin – localhost:8081 works – so how do they do it.
All I want to create is an Php-Api in one docker-compose file and the frontend in a second using the same network {scorpionet}
What Am I doing wrong?
So I’m not sure if this is allowed buthere goes.
You can find the full code on my github repo
version: "3"
services:
back-app:
container_name: back-app
build:
context: ./dockerfiles
dockerfile: php.dockerfile
image: site
restart: unless-stopped
volumes:
- ./site:/var/www
networks:
- scorpionet
back-server:
container_name: back-server
build:
context: ./dockerfiles
dockerfile: nginx.dockerfile
image: nginx:alpine
restart: unless-stopped
ports:
- "80:80"
volumes:
- ./site:/var/www
- ./config/nginx/:/etc/nginx/conf.d/
depends_on:
- back-app
- back-db
networks:
- scorpionet
back-db:
container_name: back-db
platform: linux/x86_64
image: mysql:8
env_file:
- ./env/db.env
ports:
- "3306:3306"
volumes:
- dbdata:/var/lib/mysql
networks:
- scorpionet
back-phpmyadmin:
container_name: back-phpmydmin
image: phpmyadmin/phpmyadmin
env_file:
- ./env/phpmyadmin.env
ports:
- "8081:80"
networks:
- scorpionet
volumes:
dbdata:
driver: local
networks:
scorpionet:
name: scorpionet
driver: bridge
3
Answers
I think I found the issue
The issue is the naming conflict between my app.conf file of Ngnix ('line 10': app) and the container name of my PHP ('back-app'). I'll have to test this once behind my computer.
containers running inside private docker network so localhost isn’t defined, instead use the name of the container as you specified on docker-compose.yml file.
for example inside your frontend application you will need to communicate with backend so instead of calling
localhost
you will callbackend
for example -where backend is the name of the container as you specified in docker-compose file.WORKING – cool
So after a few bug fixes discovered that Nginx could find its conf file.
So modified the docker-compose file.
Also, discovered declaring your networks first before using them seems to work better or is it just me?