Using Docker to localhost PHP

Another reminder for myself (or my students), this time how to use Docker to localhost PHP.

Download Docker from docker.com

Localhost php

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

Use

docker ps

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).

Use

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/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s