Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
399 views
in Technique[技术] by (71.8m points)

Docker bridge network curl request

I have two docker-compose file.

Firstly upped backend container and inspect the container and copy ip address for extra_hosts for frontend docker-compose file and than upped frontend. But I cant curl port of backend container from frontend container. I get connection time out error. How can I solve the problem?

    version: '3'
    
    services:
      frontend:
        build:
          context: .
          dockerfile: Dockerfile.dev
        image: test/frontend:dev
        container_name: test_frontend_dev_1
        ports:
          - "80:8080"
        extra_hosts:
          - "api-test.local:192.168.144.2"      
        # all below is not necessary in final state
        networks:
          - test_network
        volumes:
          - .:/var/www/html
          - .docker/nginx/nginx.conf:/etc/nginx/nginx.conf
          - .docker/config/php.ini:/usr/local/etc/php/conf.d/custom.ini
        # user: root
        #command: sh
    networks:
      test_network:
        driver: bridge
    version: '3'
    
    services:
      backend:
        build:
          context: .
          dockerfile: Dockerfile.dev
        image: test/backend:dev
        container_name: test_backend_dev_1
        ports:
          - "8888:8080"
        expose:
          - 8080
        # all below is not necessary in final state
        volumes:
          - .:/var/www/html
        # user: root
        #command: sh
      db:
        image: mysql:5.7
        restart: always
        environment:
          MYSQL_DATABASE: 'test'
          # So you don't have to use root, but you can if you like
          MYSQL_USER: 'user'
          # You can use whatever password you like
          MYSQL_PASSWORD: 'root'
          # Password for root access
          MYSQL_ROOT_PASSWORD: 'root'
        ports:
          # <Port exposed> : < MySQL Port running inside container>
          - '3306:3306'
        expose:
          # Opens port 3306 on the container
          - '3306'
          # Where our data will be persisted
        volumes:
          - my-db:/var/lib/mysql
        networks:
          - test_network
    networks:
      test_network:
        driver: bridge
    ## Names our volume
    volumes:
      my-db:
question from:https://stackoverflow.com/questions/65913938/docker-bridge-network-curl-request

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...