Skip to content

Instantly share code, notes, and snippets.

@willitscale
Last active August 28, 2023 07:32
Show Gist options
  • Save willitscale/67b8b4da61acc94a4153d197a1a3d379 to your computer and use it in GitHub Desktop.
Save willitscale/67b8b4da61acc94a4153d197a1a3d379 to your computer and use it in GitHub Desktop.
PHP + MySQL Docker

MySQL + PHP Docker

To build and run the containers execute:

docker-compose up

To stop the containers execute:

docker-compose stop

To start stopped containers execute:

docker-compose start

To remove all stopped containers execute:

docker-compose rm

Within the PHP docker container you should be able to connect to MySQL with:

<?php
$mysqli = new mysqli('db01', 'my_user', 'my_password', 'my_db');
version: "3"
services:
db01:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root_pass
MYSQL_DATABASE: my_db
MYSQL_USER: my_user
MYSQL_PASSWORD: my_pass
ports:
- "9906:3306"
networks:
- default
www01:
build: .
ports:
- "80:80"
volumes:
- ./src:/var/www/html/
networks:
- default
depends_on:
- db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment