Skip to content

Latest commit

 

History

History
232 lines (204 loc) · 8.98 KB

File metadata and controls

232 lines (204 loc) · 8.98 KB

How to set up the environment from scratch

Docker & Docker Compose

Nginx

MariaDB

  • Dockerfile
    • Install mariadb-server and create appropriate system user.
  • Configuration
    • Prepare a mariadb.source for the key to installing mariadb-server from the official repository.
    • Comment out "bind-address" from the 50-server.cnf/my.cnf (default is localhost) in order to allow connections from any address.
      • these files are located just as references only; the actual configuration is applied directly in the Dockerfile.
  • Database installation:
    • Reinitialize the system database with remote root access disabled and with anonymous users removed.
    • Create WordPress database using mariadb-client.
    • These steps are executed in the docker-entrypoint.sh after the container creation.

PHP-FPM

  • Dockerfile
    • Install PHP with PHP-FPM, MySQL support.
    • This image is used as a base image for PHP-FPM, WordPress and Adminer containers.
  • Configuration
    • Configure:
      • php-fpm.conf
        • Set daemonize = no
        • Set include=/usr/local/etc/php-fpm.d/\*.conf (The upstream default incorrectly sets this to include=NONE/etc/php-fpm.d/*.conf)
      • php.ini
        • Set cgi.fix_pathinfo=0 to prevent Nginx from passing requests to the PHP-FPM backend if the file does not exist, allowing us to prevent arbitrarily script injection.
      • www.conf
        • Set clear_env = no to all environment variables available to PHP code; via getenv(), $_ENV and $_SERVER that are to be used in wp-config-docker.php

WordPress

Redis

  • Dockerfile
    • Download and build source files for Redis.
  • Configuration
    • Configure:
      • redis.conf
        • Comment out bind 127.0.0.1 -::1 to listen on all interfaces.
        • Overwrite protected-mode yes to protected-mode no to allow connections from other containers.
        • Configure memory limits:
          • maxmemory 10mb
          • maxmemory-policy allkeys-lfu, all the keys will be evicted using an approximated LRU algorithm as long as we hit the 10 megabyte memory limit.
          • Redis cache configuration

Adminer

  • Dockerfile
    • Copy PHP-FPM binaries from the base image.
    • Download the adminer.php.

Vsftpd

  • Dockerfile
    • Build vsftpd from source following the INSTALL file.
  • Configuration
    • vsftpd.conf
      • Set listen=YES to run vsftpd in standalone (no-daemonized) mode
      • Set anonymous_enable=YES to allow access by an anonymous user ftp to the server without password
      • Configure pasv_min_port / pasv_max_port for passive mode, a range of ports to be opened for data transfer.
    • Ensure the firewall allows the port range properly.
      • Port 21 (Control Port)
        • This is the default, well-known port for FTP, used by the client to connect to the server and send commands like USER, PASS, LIST, GET, or PUT. It manages the entire FTP session, but not the actual file data.
      • Port 20 (Data Port - Active Mode)
        • In Active FTP, once a data transfer is requested, the server initiates a connection back to the client on its (client's) specified data port, often port 20 on the server side, to send the file.
      • Dynamic Ports (Passive Mode)
        • The server tells the client which port to use, and the client then connects to that specific port on the server for the data transfer.
    • Check the accessibility with ftp ftp://localhost -P 21 inside a container. see ftp --help

Gunicorn/Flask (Static Site)

  • Dockerfile
    • Install python3 and dependencies such as Flask, gunicorn.
    • Run gunicorn with the appropriate bind address.
  • Application Structure
        tools/
        ├── app.py
        ├── requirements.txt
        │   ├── Flask
        │   ├── python-dotenv
        │   ├── watchdog
        │   ├── greenlet
        │   └── gunicorn
        └── templates/
            └── index.html

Uptime-Kuma

  • Dockerfile
    • Install Node.js for the runtime using NVM (node version manager).
    • Install pm2
    • Clone the Uptime-kuma repository and run server.js.
  • Configuration
    • /etc/hosts
      • Sets the domain name as a host entry so it can be resolved.
      • In this project, Docker compose manages this using the extra_host attribute.

Other configurations

  • Domain name
    • Configure the domain name
      • Edit /etc/hosts so the domain name points to the local IP (host) address.
  • Firewall setup
    • Ppen the ports:
      • 443 for HTTPS connections.
      • 20-21 and a dynamic port range(1024-1048 in this case) for the FTP server.

How to build and launch the project using the Makefile and Docker Compose

Using the Makefile:

make build
make up

Or simply run:

make

Using Docker Copmose:

docker build srcs/requirements/tools/php-fpm -t php-fpm-base:1.0.0
docker compose -f srcs/docker-compose.yml build
docker compose -f srcs/docker-compose.yml up -d

Note: The PHP-FPM base image must be built first.

If you modified one of the Dockerfiles, you can rebuild only the corresponding image:

make build SERVICE="<service name>"

The commands to manage the containers, images, networks and volumes

List all containers, images, networks and volumes:

make ls

Start containers

make up

Stop containers and remove them (but keep volumes):

make down

or

make rmc

Remove images:

make rmi

Remove volumes:

make rmv

Remove networks:

make rmn

Remove unused system files:

make prune

Remove everything:

make clean

To execute a command in a specific running container, run the following command and then specify a service name listed in docker-compose.yml and the command:

make exec

To run a container and execute a command from an specific image, run the following command and then specify a service name listed in docker-compose.yml and the command:

make run

Note:

Even if you remove Docker volumes, the data in the host’s binded paths persists. When new Docker volumes are created, these host paths are automatically re-bound to them.

If a container path that is mounted to a Docker volume contains data during the build process, and the volume is later bound to a host path, the data on the host overrides the existing container data.

To completely clean everything and start from scratch, you must also delete the host data. Use:

sudo make rm_hostdb

You can inspect the host paths that are binded to Docker volumes with:

make hostdb

Where the project data is stored and how it persists

Project data is persisted using Docker volumes, which is stored within a directory on the Docker host and mounted into the container. A path on the host machine is mounted the volume so that you can see the data from the path.

  • Host path: /host/tmitsuya/data
  • Data for WordPress, MariaDB, Adminer, Uptime-kuma is stored in this path.