G
G
GrimJack2017-05-14 16:45:29
System administration
GrimJack, 2017-05-14 16:45:29

How to forward mysql container to web server container?

docker-compose.yml
db:
  image: mysql:5.7
  ports:
    - "3306:3306"
  environment:
    - MYSQL_ROOT_PASSWORD=nimda2017
    - MYSQL_USER=october
    - MYSQL_PASSWORD=secret
    - MYSQL_DATABASE=myAppDB
web:
  image: igontarev/php-server
  ports:
    - "80:80"
    - "443:443"
  links:
    - db
  volumes:
    - ./www:/var/www
    - ./sites:/etc/nginx/sites-enabled
    - ./logs/nginx:/var/log/nginx
    - ./logs/php:/var/log/php
    - ./cron:/etc/cron.d
    - ./supervisor:/etc/supervisor/conf.d
    - ./letsencrypt:/etc/letsencrypt
    - ./lib/letsencrypt:/var/lib/letsencrypt

When installing applications inside the web container, I cannot reach the database by localhost (SQLSTATE[HY000] [2002] No such file or directory) and by server ip ().
However, mysql workbench can connect to the database using the server's ip
. How can I resolve the issue?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2017-05-15
@GrimJack

Here you have it written in the description of the web
links service:
- db
####
It would be more correct and clear to write
links:
- db:db
)
####
this means who the "db" service container for the "web" service will be available on address db
localhost inside the container will point to this container itself, host ip to the host itself. Of course, you can get to the database using the host IP, because the port is forwarded (which is what your mysql workbench does), but apparently the docker adds this iptables rule only for external networks.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question