From 1dd71608b00a38467448680393702531979fa4ae Mon Sep 17 00:00:00 2001 From: Kethavath Siva Naik Date: Sat, 24 Oct 2020 10:09:44 +0530 Subject: [PATCH] Docker-Compose to setup LAMP --- Dockerfile_LAMP/Dockerfile | 19 +++++++++++++ Dockerfile_LAMP/docker-compose.yml | 28 ++++++++++++++++++ Dockerfile_LAMP/scripts/apache | 2 ++ Dockerfile_LAMP/scripts/mysql | 3 ++ Dockerfile_LAMP/scripts/start_service.sh | 36 ++++++++++++++++++++++++ 5 files changed, 88 insertions(+) create mode 100644 Dockerfile_LAMP/Dockerfile create mode 100644 Dockerfile_LAMP/docker-compose.yml create mode 100644 Dockerfile_LAMP/scripts/apache create mode 100644 Dockerfile_LAMP/scripts/mysql create mode 100644 Dockerfile_LAMP/scripts/start_service.sh diff --git a/Dockerfile_LAMP/Dockerfile b/Dockerfile_LAMP/Dockerfile new file mode 100644 index 0000000..c690b52 --- /dev/null +++ b/Dockerfile_LAMP/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:18.04 + +ENV DEBIAN_FRONTEND=noninteractive +RUN apt-get update -y +RUN apt-get install apache2 -y +RUN apt-get install libapache2-mod-php php -y +COPY index.php /var/www/html/ +RUN apt-get install libaio1 libaio-dev +RUN apt-get install mysql-server -y +RUN usermod -d /var/lib/mysql/ mysql +RUN apt-get install net-tools -y +RUN apt-get install curl -y +EXPOSE 80 +EXPOSE 3306 +COPY ./scripts/apache apache +COPY ./scripts/mysql mysql +COPY ./scripts/start_service.sh start_service.sh + +CMD ./start_service.sh diff --git a/Dockerfile_LAMP/docker-compose.yml b/Dockerfile_LAMP/docker-compose.yml new file mode 100644 index 0000000..fb6b5d5 --- /dev/null +++ b/Dockerfile_LAMP/docker-compose.yml @@ -0,0 +1,28 @@ +version: '3.3' + +services: + lamp_img: + build: ./ + lamp: + image: dockercompose_lamp_img + volumes: + - db_data:/var/lib/mysql + restart: always + environment: + MYSQL_ROOT_PASSWORD: rootpass + MYSQL_DATABASE: lamp + MYSQL_USER: lamp + MYSQL_PASSWORD: lamp + tty: true + ports: + - target: 80 + published: 80 + protocol: tcp + mode: bridge + - target: 3306 + published: 3306 + protocol: tcp + mode: bridge + +volumes: + db_data: {} diff --git a/Dockerfile_LAMP/scripts/apache b/Dockerfile_LAMP/scripts/apache new file mode 100644 index 0000000..699e5bc --- /dev/null +++ b/Dockerfile_LAMP/scripts/apache @@ -0,0 +1,2 @@ +#!/bin/bash +/etc/init.d/apache2 start diff --git a/Dockerfile_LAMP/scripts/mysql b/Dockerfile_LAMP/scripts/mysql new file mode 100644 index 0000000..ba44c4c --- /dev/null +++ b/Dockerfile_LAMP/scripts/mysql @@ -0,0 +1,3 @@ +#!/bin/bash + +/etc/init.d/mysql start diff --git a/Dockerfile_LAMP/scripts/start_service.sh b/Dockerfile_LAMP/scripts/start_service.sh new file mode 100644 index 0000000..3289cfd --- /dev/null +++ b/Dockerfile_LAMP/scripts/start_service.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# Start the first process +./apache -D +status=$? +if [ $status -ne 0 ]; then + echo "Failed to start apache: $status" + exit $status +fi + +# Start the second process +./mysql -D +status=$? +if [ $status -ne 0 ]; then + echo "Failed to start mysql: $status" + exit $status +fi + +# Naive check runs checks once a minute to see if either of the processes exited. +# This illustrates part of the heavy lifting you need to do if you want to run +# more than one service in a container. The container exits with an error +# if it detects that either of the processes has exited. +# Otherwise it loops forever, waking up every 60 seconds + +while sleep 60; do + ps aux |grep apache |grep -q -v grep + PROCESS_1_STATUS=$? + ps aux |grep mysql|grep -q -v grep + PROCESS_2_STATUS=$? + # If the greps above find anything, they exit with 0 status + # If they are not both 0, then something is wrong + if [ $PROCESS_1_STATUS -ne 0 -o $PROCESS_2_STATUS -ne 0 ]; then + echo "One of the processes has already exited." + exit 1 + fi +done