docker-alpine
docker-alpine copied to clipboard
Issue with Resolving container's URL
I am using alpine based image to run my vue front end app. I am building three services' containers using docker-compose.yml file below: from "web", (tomcat image) I can resolve and querry the database using service name "database". The issue is within alpine based "imbook-front" image. When I ping or curl "web" or assigned IP every thing work fine. but when I use ajax in codes, the name cant be resolved, when I use the assigned IP, the request times out. Help me if any of us knows what could be happening
services: web: build: context: ./ dockerfile: Dockerfile.txt ports: - 8081:8081 networks: testing_net: ipv4_address: 172.28.0.4
database:
#image: mysql:5.7
build:
context: ./
dockerfile: dockerfile_mysql.txt
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD:
root
aimbook-front:
image: denislohan/aimbook-front
ports:
- 80:8080
networks: testing_net: ipam: driver: default config: - subnet: 172.28.0.0/16
does it work another way with lets say ubuntu based image?
@jaguardev I have an other docker container in the network running the following
NAME="Debian GNU/Linux" VERSION_ID="9" VERSION="9 (stretch)" ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"
It is accessing "database" hostname (which is a service name for mysql image) in my docker-compose.yml
Your compose file/infrastructure is wrong. It is not the Docker/Alpine issue.
If WEB service is backend, then AJAX (frontend) also needs to access it. Basically:
- Add two networks - backend, frontend
- put WEB and DB on backend network
- put WEB and FRONT on frontend network
- AJAX request should be called to specified IP address/localhost (plus published port) or use reverse proxy container for transparrent backend access.
@ViltusVilks you answer guided me. I finally realised Ajax is not part of my network as it running in the browser. i decided to use a reverse proxy. I added nginx in my network and every think work like a charm