Exemple de docker amb Apache, PHP i MySQL
La revisió el 22:18, 12 gen 2025 per Jordi Binefa (discussió | contribucions) (→Xarxa local de contenidors docker)
Directori de treball
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