Riassunto da copia ed incolla con piccole modifiche ai comandi dell’ottimo tutorial: https://www.pascallandau.com/blog/php-php-fpm-and-nginx-on-docker-in-windows-10/
PHP-CLI
# start php-cli and mount current dir to /var/www docker run -di --name docker-php -v ./:/var/www php:8.1-cli # enter the container shell docker exec -it docker-php bash # check php version php -v # run php script form the mounted dir php /var/www/index.php
NGINX
# start nginx docker run -di --name docker-nginx -p 80:80 nginx:latest # enther nginx container shell docker exec -it docker-nginx bash # get nginx config files and paths nginx -V # how to test a custom index file sed -i "s#/usr/share/nginx/html#/var/www#" /etc/nginx/conf.d/default.conf mkdir -p /var/www echo "Hello world!" > /var/www/index.html nginx -s reload
Mettere insieme le due cose con docker compose
Clonare il repository https://github.com/Sampozzo/docker-php-tutorial (fork del tutorial menzionato all’inizio dell’articolo) e fare il checkout del ramo “part 1”
sul file docker-compose.yml è possibile bypassare la creazione delle immagini custom ed utilizzare quelle ufficiali sostituendo i parametri di build con quelli di image come di seguito:
# tell docker what version of the docker-compose.yml were using version: '3' # define the network networks: web-network: # start the services section services: # define the name of our service # corresponds to the "--name" parameter docker-php-cli: # define the directory where the build should happened, # i.e. where the Dockerfile of the service is located # all paths are relative to the location of docker-compose.yml image: php:8.1-cli # reserve a tty - otherwise the container shuts down immediately # corresponds to the "-i" flag tty: true # mount the app directory of the host to /var/www in the container # corresponds to the "-v" option volumes: - ./app:/var/www # connect to the network # corresponds to the "--network" option networks: - web-network docker-nginx: image: nginx:latest # defines the port mapping # corresponds to the "-p" flag ports: - "80:80" tty: true volumes: - ./app:/var/www - ./nginx/conf.d:/etc/nginx/conf.d networks: - web-network docker-php-fpm: image: php:8.1-fpm tty: true volumes: - ./app:/var/www networks: - web-network
# avviare con: docker-compose up -d # fermare con docker-compose down
Lascia un commento