Docker 桥接网络 curl 请求

时间:2021-01-27 06:29:41

标签: docker docker-compose

我有两个 docker-compose 文件。

首先升级后端容器并检查容器并复制前端docker-compose文件的extra_hosts的IP地址,然后升级前端。但是我不能从前端容器卷曲后端容器的端口。我收到连接超时错误。我该如何解决问题?

    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:

0 个答案:

没有答案