docker-alpine icon indicating copy to clipboard operation
docker-alpine copied to clipboard

Issue with Resolving container's URL

Open dniwemugisha opened this issue 6 years ago • 4 comments

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

dniwemugisha avatar Oct 24 '18 11:10 dniwemugisha

does it work another way with lets say ubuntu based image?

jaguardev avatar Oct 26 '18 11:10 jaguardev

@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

dniwemugisha avatar Oct 26 '18 14:10 dniwemugisha

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:

  1. Add two networks - backend, frontend
  2. put WEB and DB on backend network
  3. put WEB and FRONT on frontend network
  4. AJAX request should be called to specified IP address/localhost (plus published port) or use reverse proxy container for transparrent backend access.

ViltusVilks avatar Oct 31 '18 08:10 ViltusVilks

@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

dniwemugisha avatar Mar 30 '19 10:03 dniwemugisha