Docker-compose port forwarding

Viewed 10760

I have a website hosted on shared hosting on production. The website connects to the database via localhost in the code. In my docker-compose I have a php:5.6-apache and mysql:5.6 instance.

Is there any way to tell docker-compose to have port 3306 on the web container port forwarded to 3306 on the db container, so that when the web container tries to connect to localhost on 3306 it gets sent to db on 3306 and also share port 80 on the web container to the outside world?

Current docker-compose.yml:

version: "3"

services:
  web:
    build:  .
    #image: php:5.6-apache
    ports:
     - "8080:80"
    environment:
     - "APP_LOG=php://stderr"
     - "LOG_LEVEL=debug"
    volumes:
     - .:/var/www/html
    network_mode: service:db # See https://stackoverflow.com/a/45458460/95195
#    networks:
#     - internal
    working_dir: /var/www
  db:
    image: mysql:5.6
    ports:
     - "3306:3306"
    environment:
      - "MYSQL_XXXXX=*****"
    volumes:
      - ./provision/mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
#    networks:
#     - internal

networks:
  internal:
    driver: bridge

Current error:

ERROR: for web Cannot create container for service web: conflicting options: port publishing and the container type network mode

1 Answers
Related