> For the complete documentation index, see [llms.txt](https://kymbrik3.gitbook.io/programming/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kymbrik3.gitbook.io/programming/how-to-connect-locally-hosted-mysql-database-with-the-docker-container.md).

# Как подключиться к хосту локальному (к бд, например) из докер контейнера

1\) Помогло только использование network\_mode: host

Т.е. в таком случае сеть докера как бы вливается в сеть локальную.

Пример:

```
version: '3'

services:

  web:
    container_name: picfind-web
    image: nginx:1.15.10-alpine
    restart: always
    ports: ["86:80"]
    volumes:
      - ../../:/app
      - ../logs:/logs
      - ../common/host.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - app
    network_mode: host
```

Сервисы в конфиге, которые указывались по имени днс, теперь нужно указать как localhost. И видимо эти сервисы не должны перекрывать локальные порты:

Плюс значение **ports** не имеет значение в docker compose. Нужно указать свободный локальный порт в конфиге нгинкс такой же, что и был в докер-контейнер, чтобы был таким же, что и раньше:

Было:&#x20;

```
server {
    charset utf-8;
    client_max_body_size 256M;

    listen 80 default_server;

    server_name localhost;
    root        /app;
    index       index.php;

    access_log  /logs/access.log;
    error_log   /logs/error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_read_timeout 3600;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

```

Стало:&#x20;

```
server {
    charset utf-8;
    client_max_body_size 256M;

    listen 86 default_server;

    server_name localhost;
    root        /app;
    index       index.php;

    access_log  /logs/access.log;
    error_log   /logs/error.log;

    location / {
        # Redirect everything that isn't a real file to index.php
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass localhost:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_read_timeout 3600;
        fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
    }

    location ~ /\.(ht|svn|git) {
        deny all;
    }
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kymbrik3.gitbook.io/programming/how-to-connect-locally-hosted-mysql-database-with-the-docker-container.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
