[PDO → DB connection with docker, PHP]

How to connect to DB in another container with PDO from inside docker container with PHP. Note that the host name is just the container name with the DB

user and password follow docker-compose.yml.

PDO part

$db = new PDO('mysql:host=docker-practice_mysql_1;dbname=restaurant','root','pass');

Container list (terminal)

docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
												docker-practice_mysql_1

Recommended Posts

[PDO → DB connection with docker, PHP]
[Docker] Connection with MySQL
Php settings with Docker
Disposable PHP with Docker
Try DB connection with Java
[Java] Connection with local DB (IntelliJ + SpringBoot)
Lightweight PHP 7.4 development environment created with Docker
db connection notes
DB connection method-JDBC
Launch MariaDB with Docker
Rails deploy with Docker
Run Pico with docker
Explode Docker with WSL2
Use Puphpeteer with Docker
Operate Emby with Docker
Try WildFly with Docker
Use ngrok with Docker
Run Payara with Docker
Getting Started with Docker
Debug the VSCode + Docker + PHP development environment with XDebug.
Install Composer with Docker
I tried to make an introduction to PHP + MySQL with Docker
[PHP8] Install and use PECL YAML function (YAML parser) with Docker
Spring Boot application that specifies DB connection settings with parameters
Pytorch execution environment with Docker
Use GDAL with Python with Docker
[Template] MySQL connection with Java
Deploy with EC2 / Docker / Laravel
Run TAO Core with Docker
Docker management with VS Code
DB connection settings Spring-Boot application.properties
Set up GitLab with docker
[Vscode xdebug3.0 x PHP x Docker]
Run Rails whenever with docker
Get started with DynamoDB with docker
Docker autostart settings with wsl2
Connect to DB with Java
[Docker] Rails 5.2 environment construction with docker
Spring Boot starting with Docker
Build docker environment with WSL
Error with db: migrate: reset
Version control CocoaPods with Docker
Web application built with docker (1)
I tried BIND with Docker
Spring Boot DB connection pool
React environment construction with Docker
Build DynamoDB local with Docker
VisualVM (JMX connection) with Kubernetes
[Docker] Use whenever with Docker + Rails
Using PlantUml with Honkit [Docker]
Prepare a transcendentally simple PHP & Apache environment on Mac with Docker