Running LAMP in a Docker Container
We will use a prebuilt Docker container which provides Linux, Apache, MySQL (MariaDB) and PHP (hence the Name LAMP) in a preconfigured and easy to use way. Follow this tutorial to get it up and running in no time.
The commands are meant to be run from within Terminal.
Creating the Container
podman image pull fauria/lamp:latest
mkdir ~/www
podman run -p 8080:80 --name lamp -d -v /sysroot/home/$(whoami)/www:/var/www/html docker.io/fauria/lamp
This will fetch the necessary Docker Image, create our Web-root directory directly in our home directory, create the container for LAMP and start it immediatly. From this point on, you can just put files into the www directory and point your browser to http://localhost:8080 to view it:
(I’ve just put a single file in it, index.php
with the following content):
<?php phpinfo(); ?>
Running something inside the container
Sometimes you want to run some application inside the container, like for example mysql
to perform some database administration tasks. Use
podman exec -it lamp /bin/bash
To get a Bash-prompt running inside the container. From there you can run these things. Exit with exit
or press Ctrl-D
Managing the container
You need to start the container manually after a system boot. Use:
podman start lamp
to start it. Use podman stop lamp
to stop it. You can also verify if the container is running with:
podman ps --all
which will show the state of all currently running containers, something like:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d2c9a273c21 docker.io/fauria/lamp:latest /usr/sbin/run-lam... 9 minutes ago Up 9 minutes ago 0.0.0.0:8080->80/tcp lamp