Skip to content

A simple LAMP image using Ubuntu, Apache, PHP and MySql in a single image

License

Notifications You must be signed in to change notification settings

segitwo/docker-lamp

Repository files navigation

Docker-LAMP

Docker-LAMP is a docker image that includes the phusion base image, Apache, MySQL and PHP all in one handy package.

Build Status Dokcer Status License

Contents

Component Versions

Component Version
Apache 2.4.7
MySQL 5.5.50-0ubuntu0.14.04.1
PHP 5.5.9-1ubuntu4.19

Using the image

Building from source

docker build -t=mattrayner/lamp .
docker run -d -p 80:80 -p 3306:3306 mattrayner/lamp

Using with a Dockerfile

FROM mattrayner/lamp:latest

# Your custom commands

CMD ["/run.sh"]

MySQL

The default image comes with a root MySQL account that has no password. This account is only available locally though i.e. within your application. It is not availzble from outside your docker image.

When you first run the image you'll see a message showing your admin user password. This user can be used locally and externally. Either by connecting to port 3306 using a tool like MySQL Workbench or Sequel Pro. If you need this login later, you can run docker logs CONTAINER_ID and you should see it at the top of the log.

The image comes pre-installed with PHPMyAdmin available from /phpmyadmin. NOTE: you cannot use the root user with PHPMyAdmin.

Creating a database

So your application needs a database - you have two options...

  1. PHPMyAdmin
  2. Command line
PHPMyAdmin

Simply log in with the details mentioned above and create a database

Command Line

First, get the ID of your running container with docker ps, then run the below command replacing CONTAINER_ID and DATABASE_NAME with your required values:

docker exec CONTAINER_ID  mysql -uroot -e "create database DATABASE_NAME"

Adding your own content

The 'easiest' way to add your own content to the lamp image is using Docker volumes. This will effectively 'sync' a particular folder on your machine with that on the docker machine.

The below examples assume the following project layout and that you are running the commands from the 'project root'.

/ (project root)
/app/ (your PHP files live here)

That is to say that your project contains a folder called app containing all of your app's code.

Adding your own 'php'

docker run -i -t -p "80:80" -v ${PWD}/app:/app mattrayner/lamp

The above will run the docker image mattrayner/lamp interactively, exposeing port 80 on the host machine with port 80 on the docker container. It will then create a volume linking app/ within the project directory to /app on the containers file directory. This will load your PHP into apache.

Persisting your MySQL

docker run -i -t -p "80:80" -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp

The above will run the docker image, creating a mysql/ folder within our project. This folder will contain all of the MySQL files from the docker container. Therefore you will be able to stop/start the container and keep your databases.

You may also add -p 3306:3306 after -p 80:80 to expose the mysql sockets on your host machine.

Doing both (recommended)

docker run -i -t -p "80:80" -p "3306:3306" -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest

The above is our 'recommended' solution. It both adds your own PHP and persists database files. We have created an alias in our .bash_profile files to enable the short command ld or launch-docker.

.bash_profile alias examples

# Create a helper function to launch docker with overrideable parameters
function launchdockerwithparams {
    APACHE_PORT=80
    MYSQL_PORT=3306
    
    if ! [[ -z "$1" ]]; then
        APACHE_PORT=$1
    fi
    
    if ! [[ -z "$2" ]]; then
        MYSQL_PORT=$2
    fi

    docker run -i -t -p "$APACHE_PORT:80" -p "$MYSQL_PORT:3306" -v ${PWD}/app:/app -v ${PWD}/mysql:/var/lib/mysql mattrayner/lamp:latest
}
alias launchdocker='launchdockerwithparams $1 $2'
alias ld='launchdockerwithparams $1 $2'

Credits

This image is based on dgraziotin/lamp with a few changes to make it compatible with Concrete5.

About

A simple LAMP image using Ubuntu, Apache, PHP and MySql in a single image

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 47.2%
  • Shell 38.8%
  • PHP 13.0%
  • Makefile 1.0%