Another reminder for myself (or my students), this time how to use Docker to localhost PHP.
Download Docker from docker.com
In terminal run
docker run -d -p 80:80 -v /pathtofolder/:/var/www/html/ php:7.1-apache
-d for detach, i.e. run in background
-p for publish, i.e. publish container’s port(s) to the host
-v for volume, i.e. bind mount a volume
pathtofolder example: /Users/memm/GitHub/project1/backend/
You can check at the Docker Hub what php versions are available, other than 7.1-apache. Specific versions are on the left, to the right the get less specific, so get get the latest one, but it might break your application.
See all containers
to see details of running containers. They tend to have funny names, like gigantic_snyder if you use it as described (i.e. if no name was specified).
docker ps -a
to see all containers, not only running ones.
Remove all stopped containers with
docker rm $(docker ps -a -q)
Stop a container
To stop a container use
docker stop name
name example: gigantic_snyder
The PHP repository on Docker Hub is at https://hub.docker.com/_/php/