K
K
kolyafat2019-03-21 15:04:08
Docker
kolyafat, 2019-03-21 15:04:08

About docker compose mysql application doesn't have access by container name?

All good. I decided to ask a question, because I did not understand the moment with MySQL in the container. In .env I write DB_HOST by the name of the container,
DB_HOST=mysql
but if I don’t explicitly write the name in the mysql hosts, then the application does not see the database, for some reason it seems wrong to call the host by the IP of the container, it also seems wrong to register in the hosts. Experienced people, please tell me how to properly configure the container with the muscle so that everything unfolds with one command? Thanks in advance.

DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DOCKER_DB_PORT=3306
DB_DATABASE=glob
DB_USERNAME=root
DB_PASSWORD=123

mysql:
    hostname: ${DB_HOST}
    image: 'mysql:5.7'
    restart: always
    volumes:
      - ./docker/glob/:/var/lib/mysql/
      #- ./docker/mysql/db_data/:/usr/local/test-base/'
    environment:
      MYSQL_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_DATABASE}
      MYSQL_ALLOW_EMPTY_PASSWORD: ${DB_PASSWORD}
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
    ports:
      - ${DB_PORT}:3306 #Для клиентов
    networks:
      - default

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question