Create a simple Docker Compose project
Go to Project 4 from the git repository root:
cd projects/p04
Project structure:
.
├── Dockerfile
├── docker-compose.yml
└── www
└── index.php
The content of index.php
<?php
file_put_contents(__DIR__ . '/access.txt', date('Y.m.d. H:i:s') . "\n", FILE_APPEND);
echo 'P04<br/>';
echo nl2br(file_get_contents(__DIR__ . '/access.txt'));
the compose file
volumes:
php_www:
services:
php:
image: localhost/p04_php
build:
context: .
dockerfile: Dockerfile
volumes:
- php_www:/var/www
ports:
- "8080:80"
and the Dockerfile
FROM php:7.4-alpine
LABEL hu.itsziget.ld.project=p04
COPY www /var/www
CMD ["php", "-S", "0.0.0.0:80", "-t", "/var/www"]
Build an image and start the container using Docker Compose:
docker compose up -d
Check the container:
docker compose ps
# The name of the container: p04_php_1
Check the networks:
docker network ls
# New bridge network: p04_default
Delete the container, and networks with Docker Compose:
docker compose down
Or delete the volumes too.
docker compose down --volumes