Skip to content

Instantly share code, notes, and snippets.

@huzaifaarain
Last active February 20, 2023 10:59
Show Gist options
  • Save huzaifaarain/e40a7916d201a0b1d86a4aa01cd73fad to your computer and use it in GitHub Desktop.
Save huzaifaarain/e40a7916d201a0b1d86a4aa01cd73fad to your computer and use it in GitHub Desktop.
Minimal Docker Setup for PHP, MySQL & PhpMyAdmin

Minimal Docker Setup PHP, MySQL & phpmyadmin

Install docker

sudo apt install docker docker-compose

Navigate to your desire directory and Clone the repository

git clone https://github.com/huzaifaarain/docker-php-mysql.git ./

Edit docker-compose.yml file.

    mysql:
        container_name: your-db-container-name
        image: mysql:8.0
        command: --default-authentication-plugin=mysql_native_password
        restart: always
        environment:
        MYSQL_ROOT_PASSWORD: your-root-password
        MYSQL_DATABASE: sample_db
        MYSQL_USER: your-user
        MYSQL_PASSWORD: your-password
        ports: 
        - 7862:3306
    services:
        web:
            build:
            context: ./
            dockerfile: ./Dockerfile
            container_name: your-app-name
            depends_on: 
            - mysql
            volumes: 
            - ./:/var/www/html
            ports:
            - 7861:80
    phpmyadmin:
    container_name: huzaifaapp-phpmyadmin
    image: phpmyadmin/phpmyadmin:latest
    depends_on:
      - mysql
    ports:
      - 7863:80
    environment: 
      PMA_HOST: mysql-container-name
      PMA_PORT: 3306
    volumes:
      - /sessions

Edit Dockerfile

FROM php:7.3-apache
RUN apt update && apt upgrade -y
RUN docker-php-ext-install your-desired-php-extensions
EXPOSE 80

docker-php-ext-install

RUN docker-php-ext-install mysqli ... etc

Your Application will be up and running in no time, you can access your application in browser using:

localhost:7861 

PhpMyAdmin

localhost:7862
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment