T
T
topuserman2021-11-07 00:40:28
PHP
topuserman, 2021-11-07 00:40:28

Docker: container with mysql, do you really need to manually expose the host to the user?

Contents of docker-compose (for mysql):

mysql:
    image: mysql:8.0.4
    container_name: mysql
    restart: on-failure
    ports:
      - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}


After starting the container, the user MYSQL_USER is created, whose host=localhost is set.

Because of this, from another container, on the same network, for example, from php, you cannot reach mysql, because rights are missing. and you have to manually set the host
UPDATE user SET host='%' where user='my_user';

Is everyone facing this problem?
if so, how do they decide? And if not, why do I have such a problem?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Daria Motorina, 2021-11-07
@glaphire

I remember that I didn’t have such a problem, did you accurately configure the internal network?) There you need to create an internal network and specify it in the containers
my example

A
Alexander Karabanov, 2021-11-07
@karabanov

Official README - read Initializing a fresh instance .

V
Vasily Bannikov, 2021-11-07
@vabka


if so, how do they decide?

They create their own Dockerfile, in which they do all the necessary manipulations with the config.
PS: and don't deploy the database into containers

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question