Exemple de docker amb Apache, PHP i MySQL
Contingut
Docker php-sm9b personalitzat amb Apache i PHP
Directori de treball
Feu un directori al directori home del vostre usuari:
cd ~ mkdir php-sm9b
Accediu-hi:
cd php-sm9b
Dockerfile
Editeu Dockerfile:
nano Dockerfile
Aquest ha de ser el contingut de l'arxiu quan feu cat Dockerfile:
FROM php:8.2-apache # Instal·lació de les dependències per als mòduls PHP RUN apt-get update && \ apt-get install -y zip libzip-dev libpng-dev # Instal·lació de mòduls PHP addicionals RUN docker-php-ext-install mysqli pdo pdo_mysql gd zip
Genereu la imatge:
docker build -t php-sm9b .
Verifiqueu que heu generat la imatge fent:
docker images
Directori de treball del docker compost amb php-sm9b i MySQL
Feu un directori al directori home del vostre usuari:
cd ~ mkdir lamp-sm9
Accediu-hi:
cd lamp-sm9
Xarxa local de contenidors docker
- Verifiqueu si teniu la xarxa net de dockers al vostre sistema:
docker network inspect net
- Si no teniu net com una xarxa local de contenidors :
docker network create net
docker-compose.yml
Editeu docker-compose.yml:
nano docker-compose.yml
Aquest ha de ser el contingut de l'arxiu quan feu cat docker-compose.yml:
version: '3.8' services: web: image: php-sm9b:latest ports: - "8080:80" #this line maps your pc port to the container port - "8443:443" #this line maps your pc port to the container port - "3311:3306" #this line maps your pc port to the container port depends_on: - db #this line links this container to the db container volumes: - ./html:/var/www/html #this line maps the content of ./html in your pc to the /var/www/html of the container networks: - "net" db: container_name: sm9b_asix2_db_docker image: mysql:8.1.0 ports: - 3311:3306 environment: MYSQL_ROOT_PASSWORD: fjeclot #you can change the mysql root password here MYSQL_DATABASE: aula311 #you can change the database name here MYSQL_USER: iot MYSQL_PASSWORD: iot volumes: - ./mysql_data:/var/lib/mysql #this line maps the content of ./mysql_data in your pc to the /var/lib/mysql of the container networks: - "net" phpmyadmin: container_name: sm9b_asix2_phpmyadmin_docker image: phpmyadmin/phpmyadmin ports: - "8011:80" #this line maps your pc port to the container port depends_on: - db #this line links this container to the db container environment: PMA_HOST: db networks: - "net" volumes: certs: html: vhost: dhparam: networks: net: external: true