Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile_LAMP/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions Dockerfile_LAMP/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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: {}
2 changes: 2 additions & 0 deletions Dockerfile_LAMP/scripts/apache
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
/etc/init.d/apache2 start
3 changes: 3 additions & 0 deletions Dockerfile_LAMP/scripts/mysql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

/etc/init.d/mysql start
36 changes: 36 additions & 0 deletions Dockerfile_LAMP/scripts/start_service.sh
Original file line number Diff line number Diff line change
@@ -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