Skip to content

Commit fbc7fab

Browse files
committed
Added Vagrant+boot2docker support
1 parent b050472 commit fbc7fab

File tree

3 files changed

+63
-28
lines changed

3 files changed

+63
-28
lines changed

Dockerfile

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@ MAINTAINER Daniel Graziotin <[email protected]>
55
# tutumcloud/tutum-docker-lamp
66
# MAINTAINER Fernando Mayo <[email protected]>, Feng Honglin <[email protected]>
77

8+
ENV DOCKER_USER_ID 501
9+
ENV DOCKER_USER_GID 20
10+
11+
ENV BOOT2DOCKER_ID 1000
12+
ENV BOOT2DOCKER_GID 50
13+
814
# Tweaks to give MySQL write permissions to the app
9-
RUN useradd -r mysql -u 1000 && \
15+
RUN useradd -r mysql -u ${BOOT2DOCKER_ID} && \
1016
usermod -G staff mysql
1117

18+
RUN groupmod -g $(($BOOT2DOCKER_GID + 10000)) $(getent group $BOOT2DOCKER_GID | cut -d: -f1)
19+
RUN groupmod -g ${BOOT2DOCKER_GID} staff
20+
1221
# Install packages
1322
ENV DEBIAN_FRONTEND noninteractive
1423
RUN apt-get update && \

README.md

+37-27
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,59 @@
11
#osx-docker-mysql, a.k.a dgraziotin/mysql
22

3+
Out-of-the-box MySQL Docker image that *just works* on Mac OS X.
4+
Including write support for mounted volumes (MySQL).
5+
No matter if using the official boot2docker or having Vagrant in the stack, as well.
6+
37
osx-docker-mysql, which is known as
48
[dgraziotin/mysql](https://registry.hub.docker.com/u/dgraziotin/mysql/)
59
in the Docker Hub, is a reduced fork of
610
[dgraziotin/osx-docker-lamp](https://github.com/dgraziotin/osx-docker-lamp),
711
which is an "Out-of-the-box LAMP image (PHP+MySQL) for Docker".
812

9-
osx-docker-mysql is instead an:
10-
11-
Out-of-the-box MySQL Docker image that *just works* on Mac OS X.
12-
13-
However, it has also been tested for Docker running under GNU/Linux (Ubuntu 14.10).
14-
1513
Some info about osx-docker-mysql:
1614

1715
- It is based on [phusion/baseimage:latest](http://phusion.github.io/baseimage-docker/)
1816
instead of ubuntu:trusty.
17+
- It works flawlessy regardless of using boot2docker standalone or with Vagrant. You will need to set three enrironment varibles, though.
1918
- It fixes OS X related [write permission errors for MySQL](https://github.com/boot2docker/boot2docker/issues/581)
2019
- It lets you mount OS X folders *with write support* as volumes for
2120
- The database
2221
- If `CREATE_MYSQL_BASIC_USER_AND_DB="true"`, it creates a default database and user with permissions to that database
2322
- It is documented for less advanced users (like me)
2423

25-
2624
##Usage
2725

26+
If using Vagrant, please see the extra steps in the next subsection.
27+
2828
If you need to create a custom image `youruser/mysql`,
2929
execute the following command from the `osx-docker-mysql` source folder:
3030

31-
docker build -t youruser/mysql .
31+
docker build -t youruser/mysql .
3232

3333
If you wish, you can push your new image to the registry:
3434

35-
docker push youruser/mysql
35+
docker push youruser/mysql
3636

3737
Otherwise, you are free to use dgraziotin/mysql as it is provided. Remember first
3838
to pull it from the Docker Hub:
3939

4040
docker pull dgraziotin/mysql
4141

42+
###Vagrant
43+
44+
If, for any reason, you would rather use Vagrant (I suggest using [AntonioMeireles/boot2docker-vagrant-box](https://github.com/AntonioMeireles/boot2docker-vagrant-box)), you need to add the following three variables when running your box:
45+
46+
-`VAGRANT_OSX_MODE="true"` for enabling Vagrant-compatibility
47+
-`DOCKER_USER_ID=$(id -u)` for letting Vagrant use your host user ID for mounted folders
48+
-`DOCKER_USER_GID=$(id -g)` for letting Vagrant use your host user GID for mounted folders
49+
50+
See the Environment variables section for more options.
4251

43-
###Running your LAMP docker image
52+
###Running your MySQL docker image
4453

4554
If you start the image without supplying your code, e.g.,
4655

47-
docker run -t -i -p 3306:3306 --name db dgraziotin/mysql
56+
docker run -t -i -p 3306:3306 --name db dgraziotin/mysql
4857

4958
At [boot2docker ip] you should be able to connect to MySQL.
5059

@@ -53,7 +62,7 @@ At [boot2docker ip] you should be able to connect to MySQL.
5362
If you wish to mount a MySQL folder locally, so that MySQL files are saved on your
5463
OS X machine, run the following instead:
5564

56-
docker run -i -t -p "3306:3306" -v ${PWD}/mysql:/mysql --name db dgraziotin/mysql
65+
docker run -i -t -p "3306:3306" -v ${PWD}/mysql:/mysql --name db dgraziotin/mysql
5766

5867
The MySQL database will thus become persistent at each subsequent run of your image.
5968

@@ -83,18 +92,18 @@ with all root privileges will be created in MySQL with a random password.
8392

8493
To get the password, check the logs of the container by running:
8594

86-
docker logs [name or id, e.g., mywebsite]
95+
docker logs [name or id, e.g., mywebsite]
8796

8897
You will see an output like the following:
8998

90-
========================================================================
91-
You can now connect to this MySQL Server using:
99+
========================================================================
100+
You can now connect to this MySQL Server using:
92101

93-
mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>
102+
mysql -uadmin -p47nnf4FweaKu -h<host> -P<port>
94103

95-
Please remember to change the above password as soon as possible!
96-
MySQL user 'root' has no password but only allows local connections
97-
========================================================================
104+
Please remember to change the above password as soon as possible!
105+
MySQL user 'root' has no password but only allows local connections
106+
========================================================================
98107

99108
In this case, `47nnf4FweaKu` is the password allocated to the `admin` user.
100109

@@ -111,17 +120,18 @@ the the `MYSQL_USER_*` variables, explained below.
111120

112121
##Environment variables
113122

114-
- MYSQL_ADMIN_PASS="mypass" will use your given MySQL password for the `admin`
123+
- `MYSQL_ADMIN_PASS="mypass"` will use your given MySQL password for the `admin`
115124
user instead of the random one.
116-
- CREATE_MYSQL_BASIC_USER_AND_DB="true" will create the user `user` with db `db` and password `password`. Not needed if using one of the following three MYSQL_USER_* variables
117-
- MYSQL_USER_NAME="daniel" will use your given MySQL username instead of `user`
118-
- MYSQL_USER_DB="supercooldb" will use your given database name instead of `db`
119-
- MYSQL_USER_PASS="supersecretpassword" will use your given password instead of `password`
120-
- PHP_UPLOAD_MAX_FILESIZE="10M" will change PHP upload_max_filesize config value
121-
- PHP_POST_MAX_SIZE="10M" will change PHP post_max_size config value
125+
- `CREATE_MYSQL_BASIC_USER_AND_DB="true"` will create the user `user` with db `db` and password `password`. Not needed if using one of the following three `MYSQL_USER_*` variables
126+
- `MYSQL_USER_NAME="daniel"` will use your given MySQL username instead of `user`
127+
- `MYSQL_USER_DB="supercooldb"` will use your given database name instead of `db`
128+
- `MYSQL_USER_PASS="supersecretpassword"` will use your given password instead of `password`
129+
-`VAGRANT_OSX_MODE="true"` for enabling Vagrant-compatibility
130+
-`DOCKER_USER_ID=$(id -u)` for letting Vagrant use your host user ID for mounted folders
131+
-`DOCKER_USER_GID=$(id -g)` for letting Vagrant use your host user GID for mounted folders
122132

123133
Set these variables using the `-e` flag when invoking the `docker` client.
124134

125-
docker run -i -t -p "3306:3306" -e MYSQL_ADMIN_PASS="mypass" --name yourwebapp dgraziotin/mysql
135+
docker run -i -t -p "3306:3306" -e MYSQL_ADMIN_PASS="mypass" --name yourdb dgraziotin/mysql
126136

127137
Please note that the MySQL variables will not work if an existing MySQL volume is supplied.

run.sh

+16
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,22 @@ chown -R mysql:staff /var/run/mysqld
88
chmod -R 770 /var/lib/mysql
99
chmod -R 770 /var/run/mysqld
1010

11+
if [ -n "$VAGRANT_OSX_MODE" ];then
12+
usermod -u $DOCKER_USER_ID mysql
13+
groupmod -g $(($DOCKER_USER_GID + 10000)) $(getent group $DOCKER_USER_GID | cut -d: -f1)
14+
groupmod -g ${DOCKER_USER_GID} staff
15+
chmod -R 770 /var/lib/mysql
16+
chmod -R 770 /var/run/mysqld
17+
chown -R mysql:staff /var/lib/mysql
18+
chown -R mysql:staff /var/run/mysqld
19+
else
20+
# Tweaks to give Apache/PHP write permissions to the app
21+
chmod -R 770 /var/lib/mysql
22+
chmod -R 770 /var/run/mysqld
23+
chown -R mysql:staff /var/lib/mysql
24+
chown -R mysql:staff /var/run/mysqld
25+
fi
26+
1127
sed -i "s/bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/my.cnf
1228
sed -i "s/user.*/user = mysql/" /etc/mysql/my.cnf
1329

0 commit comments

Comments
 (0)