I have a landing page and one PHP file to send emails (feedback form). I want to test this form using Docker.
I've written this Dockerfile:
FROM php:7.4-cli
COPY . /usr/src/app
CMD [ "php", "/mail/contact_me.php"]
But it doesn't work for me.
I have the directory mail
with the PHP file in the root of the project, but I'm still unsure if the Dockerfile is correct:
FROM php:7.4-cli
or do I have to add nginx server to run the image?COPY . /usr/src/app
exactly do? Is this correct?A Dockerfile
is used when you want to create a custom image.
FROM php:7.4-cli
specifies the base image you want to customize.COPY . /usr/src/app
copie the host current directory .
into the container /usr/src/app
.CMD [ "php", "/mail/contact_me.php"]
specifies what command to run within the container.
In your case, I don't think a custom image is required.
As you need a webserver with PHP, you can use the php:7.4.3-apache
image which comes with PHP7
and Apache
webserver pre-installed. All you need to do is copy your app to your container, or use a volume. A volume is great because it actually mounts your host directory into your container, allowing you to edit your app from the host and see changes in real-time.
You can use a docker-compose.yml
file for that.
version: "2"
services:
webserver:
image: php:7.4.3-apache
ports:
- "8181:80"
volumes:
- ./app:/var/www/html
Assuming your application is located in an app
folder on your host machine, this folder will get mounted at /var/html/html
on your container. Here the 8181:80
will redirect the 8181
port on your host machine to the 80
port of your container, which is the http port.
Use this command to start your container:
docker-compose up -d
Your should see your landing page at http://localhost:8181
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With