Skip to content

Commit 5ed104b

Browse files
authored
Merge branch 'master' into htaccess-fix
2 parents 443a071 + 915488e commit 5ed104b

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

1804/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ADD supporting_files/supervisord.conf /etc/supervisor/supervisord.conf
5555
RUN rm -rf /var/lib/mysql
5656

5757
# Add MySQL utils
58-
ADD supporting_files/create_mysql_users.sh /create_mysql_users.sh
58+
ADD supporting_files/mysql_init.sh /mysql_init.sh
5959

6060
# Add phpmyadmin
6161
RUN wget -O /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PHPMYADMIN_VERSION}/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages.tar.gz

2004/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ ADD supporting_files/supervisord.conf /etc/supervisor/supervisord.conf
5555
RUN rm -rf /var/lib/mysql
5656

5757
# Add MySQL utils
58-
ADD supporting_files/create_mysql_users.sh /create_mysql_users.sh
58+
ADD supporting_files/mysql_init.sh /mysql_init.sh
5959

6060
# Add phpmyadmin
6161
RUN wget -O /tmp/phpmyadmin.tar.gz https://files.phpmyadmin.net/phpMyAdmin/${PHPMYADMIN_VERSION}/phpMyAdmin-${PHPMYADMIN_VERSION}-all-languages.tar.gz

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ With Ubuntu **20.04** and **18.04** images on the `latest-2004` and `latest-1804
2121
- [Creating a database](#creating-a-database)
2222
- [PHPMyAdmin](#phpmyadmin)
2323
- [Command Line](#command-line)
24+
- [Initialization script](#initialization-script)
25+
- [SQL initialization script](#sql-initialization-script)
2426
- [Adding your own content](#adding-your-own-content)
2527
- [Adding your app](#adding-your-app)
2628
- [Persisting your MySQL](#persisting-your-mysql)
@@ -103,10 +105,11 @@ When you first run the image you'll see a message showing your `admin` user's pa
103105
If you need this login later, you can run `docker logs CONTAINER_ID` and you should see it at the top of the log.
104106

105107
#### Creating a database
106-
So your application needs a database - you have two options...
108+
So your application needs a database - you have three options:
107109

108110
1. PHPMyAdmin
109111
2. Command line
112+
3. Initialization script
110113

111114
##### PHPMyAdmin
112115
Docker-LAMP comes pre-installed with phpMyAdmin available from `http://DOCKER_ADDRESS/phpmyadmin`.
@@ -119,6 +122,19 @@ First, get the ID of your running container with `docker ps`, then run the below
119122
docker exec CONTAINER_ID mysql -uroot -e "create database DATABASE_NAME"
120123
```
121124

125+
##### Initialization script
126+
See the [SQL initialization script section](#sql-initialization-script) for details.
127+
128+
#### SQL initialization script
129+
Optionally, you can provide a SQL script which will run immediately after MySQL has been installed and configured, allowing you to run custom SQL e.g. to create a database, users or insert custom data.
130+
131+
Please note that **the SQL initialization script runs only at the container first startup**. The script won't run if MySQL has already been configured (i.e. if the `/var/lib/mysql` contains initialized MySQL data).
132+
133+
The below command will run the docker image `mattrayner/lamp:latest` interactively, exposing port `80` on the host machine with port `80` on the docker container. It will also create a volume linking the `script.sql` file within your current folder to the `/db/init.sql` file on the container. This is where the container expects the SQL initialization script to live.
134+
135+
```bash
136+
docker run -i -t -p "80:80" -v ${PWD}/script.sql:/db/init.sql:ro mattrayner/lamp:latest
137+
```
122138

123139
## Adding your own content
124140
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 container.

supporting_files/create_mysql_users.sh renamed to supporting_files/mysql_init.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ if [ "$CREATE_MYSQL_USER" = true ]; then
3939
mysql -uroot -e "GRANT ALL PRIVILEGES ON ${_userdb}.* TO '${_user}'@'%'"
4040
fi
4141

42+
if [[ -e /db/init.sql ]]; then
43+
echo "=> Initializing the database"
44+
45+
mysql -uroot < /db/init.sql
46+
fi
47+
4248
echo "=> Done!"
4349

4450
echo "========================================================================"

supporting_files/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ if [[ ! -d $VOLUME_HOME/mysql ]]; then
106106
fi
107107

108108
echo "=> Done!"
109-
/create_mysql_users.sh
109+
/mysql_init.sh
110110
else
111111
echo "=> Using an existing volume of MySQL"
112112
fi

0 commit comments

Comments
 (0)