You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Adding your own content](#adding-your-own-content)
25
27
-[Adding your app](#adding-your-app)
26
28
-[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
103
105
If you need this login later, you can run `docker logs CONTAINER_ID` and you should see it at the top of the log.
104
106
105
107
#### 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:
107
109
108
110
1. PHPMyAdmin
109
111
2. Command line
112
+
3. Initialization script
110
113
111
114
##### PHPMyAdmin
112
115
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
119
122
docker exec CONTAINER_ID mysql -uroot -e "create database DATABASE_NAME"
120
123
```
121
124
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
+
```
122
138
123
139
## Adding your own content
124
140
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.
0 commit comments