How to create a docker-based LAMP stack using docker-compose on Ubuntu 18.04 Bionic Beaver Linux - LinuxConfig.org

In this tutorial, we will see how to create a LAMP stack based on dockerized components: following the "one service per container" philosophy, we will assemble the environment using docker-compose, a tool to orchestrate container compositions.


This is a companion discussion topic for the original entry at https://linuxconfig.org/how-to-create-a-docker-based-lamp-stack-using-docker-compose-on-ubuntu-18-04-bionic-beaver-linux

SMaction

Hi,

I followed the instructions and modified your files for my own use. However, I am getting an error that pdo is not installed when I go to use a database connection. My docker-compose file is posted here as well as my Dockerfile:https://pastebin.com/t26mT4YK and https://pastebin.com/0RrDprbt

TIA

Dehan Louw

Great write-up, thanks! I just keep getting the error:
Uncaught Error: Class ‘mysqli’ not found in /var/www/html/events.php:6

Any idea? Everything is exactly like you said

Egidio Docile -> Dehan Louw

You are using mysqli extension. This is not included in the default php dockerfile: to include it, it’s necessary to create a custom dockerfile we the needed instructions. I’m going to update the article to include those. Thank you for your attention.

Well done,

How to link the volumes: mariadb: to host disk folder?
Thank you.

If I understand correctly, you want to create a bind mount for mariadb so that a directory in your host is mounted inside the container. Say for example you want to mount a “db” directory in your filesystem (I will assume it’s in the same folder where the docker-compose.yml file is) to /var/lib/mysql inside the container, the syntax you should use in the docker-compose.yml file is:

mariadb:
    volumes:
        - ./db:/var/lib/mysql:z

You can use both an absolute or relative path for the local directory. The suffix :z has meaning only if you are running SElinux.

I followed a similar tutorial to dockerize php application on Cloudways blog . However, that tutorial was different than this one. The method of was different. In that tutorial, the docker compose file had php and db defined in it. Then php and db dockerfiles were created to deploy the app. Are there more than one methods to do so?

Hi,
I am unable to access the page once its built and the docker-compose up command doesn’t exit.
However I can see that the container is running using docker ps -a. Also I am unable to access the webpage.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6fc5d28c12fc php:7.2.1-apache “docker-php-entrypoi…” 8 minutes ago Up 8 minutes 80/tcp, 0.0.0.0:81->81/tcp dipjyotig_php-apache_1
9f437910288a mariadb:10.1 “docker-entrypoint.s…” 16 minutes ago Up 8 minutes 3306/tcp dipjyotig_mariadb_1

Alert!: Unable to access document.

lynx: Can’t access startfile

Hi,
The ‘docker-compose up’ command doesn’t exit because by default it runs in foreground. If you want it to run in background you should use the “-d” or “–detach” option.
For the 6fc5d28c12fc container, it looks to me that you mapped port 81 of your host machine to port 81 of your container. The web server on the container uses port 80, not port 81 (unless you modified something) therefore you can’t reach it. You can still map your host port 81 to the container port 80, but in that case you should access the service by specifying the port (es http://localhost:81).

Hi,
thanks alot for the tutorial. I just learned (thx Thomas & Christian on docker slack), that “docker-compose up” will not trigger the RUN commands in Dockerfiles, since they are executed only during build process. To trigger a build, we have to run “docker-compose up --build”.

Hi, first I’d to thank for this tutorial. It’s possible to set friendly url in this configuration?

If you mean defining rewrite rules in .htaccess files, of course it’s possible!

Thanks for the work. I do have one opinion, I’ve been in the IT business for 40 years, and yaml is the worst idea I’ve ever seen. Format is NOT more important than functionality. The argument for it is that others will read my code later so formatting must be enforced. I just spent 20 min just messing with spaces and tabs just to get it to work. For future whipper snappers… how about not care about format and just give us a pretty printer after the fact to clean it up :slight_smile: