NewWork mode: your Claude Code or Codex on work calls, answering from your project's codeSkip to content
Middle+82 views

База в Docker недоступна с хоста: как зайти в неё и внести изменения?

Practice

AI answer

If the database port is not published to the host, you can connect to it from inside the container using docker exec. For example, for PostgreSQL:

docker exec -it <db-container> psql -U <user> -d <database>

For MySQL:

docker exec -it <db-container> mysql -u <user> -p <database>

With Docker Compose, it is more convenient to use the service name: docker compose exec db psql -U <user> -d <database>. If the container does not have a client installed, you can start a separate container with a client on the same Docker network. Once connected, make changes using regular SQL commands.

To connect from the host, publish the port, for example in Compose: ports: ["5432:5432"], and connect to localhost:5432. Take access settings and credentials into account. Do not edit database files directly inside a Docker volume—use a database client, and make a backup before risky changes.