Web Applications

Docker with Compose

Trust me, I'm ...

docker pull php:8.3.6-apache

Docker compose

Docker compose file

Services are defined in docker-compose.yaml file. Values for environment variables are automatically loaded from .env file.

version: '3.8'
    image: nswi153/frontend
      - 8090:80
      SERVER_URL: ''
  • restart
  • depends_on
  • healthcheck
  • volumes
  • variable defaults
  • variables and .env file

Assignment: cms


Copy practical-02/cms and practical-03/vite from previous practicals to practical-07/cms and ./vite.

Create a Dockerfile for a container hosting the web application cms. Name the image nswi153/backend. Update the source code of the application so that:

  • Database host can be set using DATABASE_HOST.
  • Database driver can be set using DATABASE_DRIVER.

Use php:8.3.6-apache as a base image.


This is a list of steps that you need to carry out to create functional Docker image for the assignment.

  • Enable rewrite and allow it is use in .htacces.
    sed -i 's/AllowOverride None/AllowOverride All/' /etc/apache2/apache2.conf
    a2enmod rewrite
  • Update package index so you can install packages. Next install requirements for Composer and pgsql.
    apt-get update
    apt-get -y --no-install-recommends install unzip libpq-dev
  • Install PHP extensions using provided script.
    docker-php-ext-install pgsql
  • Install Composer and use it to install all dependencies.

Assignment: docker compose


Create docker-compose.yaml file hosting:

  • nswi153/frontend build from ./vite
  • nswi153/backend build from ./cmd
  • database
  • adminer

Assignment: docker compose


Create Dockerfile with postgres:16.2. Automatically populate the database nswi153 with articles and authors.

Once ready utilize the image in the docker-compose file as the database. You may need to modify other files in practical-07 directory to make it work.


  • For image postgres:16.2 you can copy SQL scripts to "/docker-entrypoint-initdb.d". Those scripts get automatically executed after a database is created.
  • Declare a named volume for postgres data "postgres_data:/var/lib/postgresql/data".

You must implement and submit the assignments before 10.5.2024 23:59 UTC.

Extra content ...

Content beyond this slide is not mandatory part of the seminar. Yet it may help you with better use and understanding of Docker.

Keeping deployment up-to-date

We can employ tools like Watchtower to automatically update the containers.

Questions, ideas, or any other feedback?

Please feel free to use the anonymous feedback form.