Merge ~ubuntu-docker-images/ubuntu-docker-images/+git/mysql:readme into ~ubuntu-docker-images/ubuntu-docker-images/+git/mysql:edge

Proposed by Lucas Kanashiro
Status: Merged
Merged at revision: 472006719b522e8676eb627ac1fe208790d322da
Proposed branch: ~ubuntu-docker-images/ubuntu-docker-images/+git/mysql:readme
Merge into: ~ubuntu-docker-images/ubuntu-docker-images/+git/mysql:edge
Diff against target: 390 lines (+341/-9)
6 files modified
HACKING.md (+14/-0)
README.md (+194/-9)
examples/README.md (+44/-0)
examples/config/my-custom.cnf (+3/-0)
examples/docker-compose.yml (+14/-0)
examples/mysql-deployment.yml (+72/-0)
Reviewer Review Type Date Requested Status
Lucas Kanashiro Approve
Sergio Durigan Junior Needs Fixing
Review via email: mp+393874@code.launchpad.net

Description of the change

Improve README.

To post a comment you must log in.
Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

I'm reviewing this one.

Revision history for this message
Sergio Durigan Junior (sergiodj) wrote :

Thanks for the MP, Lucas. Just small nits to fix; otherwise it's ready to be pushed.

review: Needs Fixing
Revision history for this message
Lucas Kanashiro (lucaskanashiro) wrote :

Thanks again Sergio. Comments addressed. Merging it and updating DockerHub page.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/HACKING.md b/HACKING.md
2new file mode 100644
3index 0000000..662c988
4--- /dev/null
5+++ b/HACKING.md
6@@ -0,0 +1,14 @@
7+# Contributing
8+
9+In order to contribute to the MySQL OCI image do the following:
10+
11+* Create a new branch.
12+* Make your changes. Keep your commits logically separated. If it is fixing a bug do not forget to mention it in the commit message.
13+* Build a new image with your changes. You can use the following command:
14+
15+```
16+$ docker build -t squeakywheel/mysql:test -f Dockerfile .
17+```
18+
19+* Test the new image. Run it in some way that exercises your changes, you can also check th README.md file.
20+* If everything goes well submit a merge proposal.
21diff --git a/README.md b/README.md
22index 7056b37..4a45fdb 100644
23--- a/README.md
24+++ b/README.md
25@@ -1,14 +1,199 @@
26-## Ubuntu MySQL 8.0 OCI image
27+# MySQL | Ubuntu
28
29-This is a fork of upstream's mysql image from https://github.com/docker-library/mysql
30+## About MySQL
31
32-These are the main changes:
33-- using Ubuntu Focal 20.04 LTS as the layer
34-- installing MySQL 8.0 from Ubuntu Focal 12.04 LTS
35-- amd64 only at the moment
36+MySQL is a fast, stable and true multi-user, multi-threaded SQL database
37+server. SQL (Structured Query Language) is the most popular database query
38+language in the world. The main goals of MySQL are speed, robustness and ease
39+of use.
40
41-The entrypoint and environment variables were not changed.
42+## Tags
43
44-Bugs? Comments? Get in touch with the Ubuntu Server team at
45-https://discourse.ubuntu.com/c/server/
46+- `8.0.22-focal`, `8.0.22`, `8.0-focal`, `8.0``8-focal`, `8`, `focal`, `beta` - **/!\ this is a beta release**
47
48+### Architectures supported
49+
50+- `amd64`, `arm64`, `s390x`
51+
52+## Usage
53+
54+### Docker CLI
55+
56+```sh
57+$ docker network create mysql-net
58+# Run the server
59+$ docker run --name mysql-instance --network mysql-net --env MYSQL_ROOT_PASSWORD=My$seCret --detach squeakywheel/mysql:edge
60+# Run the client
61+$ docker run --interactive --tty --rm --network mysql-net squeakywheel/mysql:edge mysql -hmysql-instance -Uroot -p
62+```
63+
64+The password will be asked and you can enter `My$seCret`. Now, you are logged in and can enjoy your new instance.
65+
66+Since containers are ephemeral you might be interested in persist data and not initialize a new database every time you launch a new container. To do that you can use docker volumes:
67+
68+```sh
69+$ docker run --name mysql --volume /path/to/persisted/data:/var/lib/mysql --env MYSQL_RANDOM_ROOT_PASSWORD squeakywheel/mysql:edge
70+```
71+
72+#### Parameters
73+
74+| Parameter | Description |
75+|---|---|
76+| `-e TZ=UTC` | Timezone |
77+| `-e MYSQL_ROOT_PASSWORD=secret_for_root` | Set the password for the `root` user. This option is **mandatory** and **must not be empty**. |
78+| `-e MYSQL_PASSWORD=secret` | Set the password for the `MYSQL_USER` user. |
79+| `-e MYSQL_USER=john` | Create a new user with superuser privileges. This is used in conjunction with `MYSQL_PASSWORD` |
80+| `-e MYSQL_DATABASE=db_test` | Set the name of the default database. |
81+| `-e MYSQL_ALLOW_EMPTY_PASSWORD=yes` | Set up a blank password for the `root` user. **This is not recommended to be used in production, make sure you know what you are doing**. |
82+| `-e MYSQL_RANDOM_ROOT_PASSWORD=yes` | Generate a random initial password for the `root` user using `pwgen`. It will be printed in the logs, search for `GENERATED ROOT PASSWORD`. |
83+| `-e MYSQL_ONETIME_PASSWORD=yes` | Set `root` user as experide once initialization is complete, forcing a password change on first login. |
84+| `-e MYSQL_INITSB_SKIP_TZINFO=yes` | Timezone data is automatically loaded via entrypoint script, set this variable to any non-empty value to disable it. |
85+
86+#### Initialization Scripts
87+
88+One can also add initialization scripts to their containers. This includes `*.sql`, `.sql.gz`, and `*.sh` scripts, and you just need to put them inside the `/docker-entrypoint-initdb.d` directory inside the container. After MySQL initialization is done and the default database and user are created, the scripts are executed in the following order:
89+
90+* Run any `*.sql` files in alphabetically order. By default the target database is specified via `MYSQL_DATABASE`.
91+* Run any executable `*.sh` scripts in alphabetically order.
92+* Source any non-executable `*.sh` scripts in alphabetically order.
93+
94+All of this is done before the MySQL service is started. Keep in mind if your database directory is not empty (contains pre-existing database) they will be left untouched.
95+
96+#### Database Configuration
97+
98+You can pass your own configuration files to the container doing the following:
99+
100+```sh
101+$ docker run --name mysql --volume /path/to/mysql/config/files/:/etc/mysql/mysql.conf.d/ --env MYSQL_ROOT_PASSWORD=P@sSwd squeakywheel/mysql:edge
102+```
103+
104+#### Debugging
105+
106+In case you need to debug what it is happening with the container you can run `docker logs <name_of_the_container>`. But if you want to get access to an interactive shell run:
107+
108+```sh
109+$ docker exec -it <name_of_the_container> /bin/bash
110+```
111+
112+To see how to use the MySQL OCI image with `docker-compose` and `kubernetes` check the `examples/README.md` file.
113+
114+## Deploy with Kubernetes
115+
116+You can use your favorite Kubernetes distribution; if you don't have one, consider [installing MicroK8s](https://microk8s.io/).
117+
118+With microk8s running, enable the `dns` and `storage` add-ons:
119+```sh
120+$ microk8s enable dns storage
121+ ```
122+
123+Create a configmap for the configuration file (write your `my.cnf` file based on the upstream documentation [here](https://dev.mysql.com/doc/refman/8.0/en/mysql-command-options.html)):
124+
125+```sh
126+$ microk8s kubectl create configmap mysql-config --from-file=main-config=config/my-custom.cnf
127+```
128+
129+Use the sample deployment yaml provided [here](https://git.launchpad.net/~canonical-server/ubuntu-server-oci/+git/mysql/plain/examples/mysql-deployment.yml).
130+
131+<details>
132+ <summary>Apply the `mysql-deployment.yml` (click to expand)</summary>
133+
134+```yaml
135+# mysql-deployment.yml
136+---
137+apiVersion: v1
138+kind: PersistentVolumeClaim
139+metadata:
140+ name: mysql-volume-claim
141+spec:
142+ accessModes:
143+ - ReadWriteOnce
144+ storageClassName: microk8s-hostpath
145+ resources:
146+ requests:
147+ storage: 500M
148+---
149+apiVersion: apps/v1
150+kind: Deployment
151+metadata:
152+ name: mysql-deployment
153+spec:
154+ replicas: 1
155+ selector:
156+ matchLabels:
157+ app: mysql
158+ template:
159+ metadata:
160+ labels:
161+ app: mysql
162+ spec:
163+ containers:
164+ - name: mysql
165+ image: squeakywheel/mysql:edge
166+ env:
167+ - name: MYSQL_RANDOM_ROOT_PASSWORD
168+ value: "yes"
169+ - name: MYSQL_PASSWORD
170+ value: "myS&cret"
171+ - name: MYSQL_USER
172+ value: "john"
173+ volumeMounts:
174+ - name: mysql-config-volume
175+ mountPath: /etc/mysql/mysql.conf.d/my-custom.cnf
176+ subPath: my-custom.cnf
177+ - name: mysql-data
178+ mountPath: /var/lib/mysql
179+ ports:
180+ - containerPort: 3306
181+ name: mysql
182+ protocol: TCP
183+ volumes:
184+ - name: mysql-config-volume
185+ configMap:
186+ name: mysql-config
187+ items:
188+ - key: main-config
189+ path: my-custom.cnf
190+ - name: mysql-data
191+ persistentVolumeClaim:
192+ claimName: mysql-volume-claim
193+---
194+apiVersion: v1
195+kind: Service
196+metadata:
197+ name: mysql-service
198+spec:
199+ type: NodePort
200+ selector:
201+ app: mysql
202+ ports:
203+ - protocol: TCP
204+ port: 3306
205+ targetPort: 3306
206+ nodePort: 30306
207+ name: mysql
208+```
209+
210+</details>
211+
212+```sh
213+$ microk8s kubectl apply -f mysql-deployment.yml
214+```
215+
216+You will now be able to connect to the MySQL server on `localhost:30306`.
217+
218+## Bugs and Features request
219+
220+If you find a bug in our image or want to request a specific feature file a bug here:
221+
222+https://bugs.launchpad.net/ubuntu-server-oci/+filebug
223+
224+In the title of the bug add `mysql: <reason>`.
225+
226+Make sure to include:
227+
228+* The digest of the image you are using, you can find it using this command replacing `<tag>` with the one you used to run the image:
229+```sh
230+$ docker images --no-trunc --quiet squeakywheel/mysql:<tag>
231+```
232+* Reproduction steps for the deployment
233+* If it is a feature request, please provide as much detail as possible
234diff --git a/examples/README.md b/examples/README.md
235new file mode 100644
236index 0000000..b07a46b
237--- /dev/null
238+++ b/examples/README.md
239@@ -0,0 +1,44 @@
240+# Running the examples
241+
242+## docker-compose
243+
244+Install `docker-compose` from the Ubuntu archive:
245+
246+```
247+$ sudo apt install -y docker-compose
248+```
249+
250+Call `docker-compose` from the examples directory:
251+
252+```
253+$ docker-compose up -d
254+```
255+
256+MySQL will be running and available via port `3306` on your host. The password of the `john` user will be `myS&cret`. To stop it run:
257+
258+```
259+$ docker-compose down
260+```
261+
262+# Microk8s
263+
264+With microk8s running, enable the `dns` and `storage` add-ons:
265+
266+```
267+$ microk8s enable dns storage
268+```
269+
270+Create a configmap for the configuration files:
271+
272+```
273+$ microk8s kubectl create configmap mysql-config \
274+ --from-file=main-config=config/my-custom.cnf
275+```
276+
277+Apply the `mysql-deployment.yml`:
278+
279+```
280+$ microk8s kubectl apply -f mysql-deployment.yml
281+```
282+
283+MySQL will be running and available via port `30306` on your host. The password of the `john` user will be `myS&cret`.
284diff --git a/examples/config/my-custom.cnf b/examples/config/my-custom.cnf
285new file mode 100644
286index 0000000..8e55230
287--- /dev/null
288+++ b/examples/config/my-custom.cnf
289@@ -0,0 +1,3 @@
290+[mysqld]
291+bind-address = 0.0.0.0
292+port = 3306
293diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml
294new file mode 100644
295index 0000000..ec0ea8f
296--- /dev/null
297+++ b/examples/docker-compose.yml
298@@ -0,0 +1,14 @@
299+version: '2'
300+
301+services:
302+ mysql:
303+ image: squeakywheel/mysql:edge
304+ network_mode: "host"
305+ ports:
306+ - 3306:3306
307+ environment:
308+ - MYSQL_RANDOM_ROOT_PASSWORD=yes
309+ - MYSQL_PASSWORD=myS&cret
310+ - MYSQL_USER=john
311+ volumes:
312+ - ./config/my-custom.cnf:/etc/mysql/mysql.conf.d/my-custom.cnf
313diff --git a/examples/mysql-deployment.yml b/examples/mysql-deployment.yml
314new file mode 100644
315index 0000000..2a30022
316--- /dev/null
317+++ b/examples/mysql-deployment.yml
318@@ -0,0 +1,72 @@
319+---
320+apiVersion: v1
321+kind: PersistentVolumeClaim
322+metadata:
323+ name: mysql-volume-claim
324+spec:
325+ accessModes:
326+ - ReadWriteOnce
327+ storageClassName: microk8s-hostpath
328+ resources:
329+ requests:
330+ storage: 500M
331+---
332+apiVersion: apps/v1
333+kind: Deployment
334+metadata:
335+ name: mysql-deployment
336+spec:
337+ replicas: 1
338+ selector:
339+ matchLabels:
340+ app: mysql
341+ template:
342+ metadata:
343+ labels:
344+ app: mysql
345+ spec:
346+ containers:
347+ - name: mysql
348+ image: squeakywheel/mysql:edge
349+ env:
350+ - name: MYSQL_RANDOM_ROOT_PASSWORD
351+ value: "yes"
352+ - name: MYSQL_PASSWORD
353+ value: "myS&cret"
354+ - name: MYSQL_USER
355+ value: "john"
356+ volumeMounts:
357+ - name: mysql-config-volume
358+ mountPath: /etc/mysql/mysql.conf.d/my-custom.cnf
359+ subPath: my-custom.cnf
360+ - name: mysql-data
361+ mountPath: /var/lib/mysql
362+ ports:
363+ - containerPort: 3306
364+ name: mysql
365+ protocol: TCP
366+ volumes:
367+ - name: mysql-config-volume
368+ configMap:
369+ name: mysql-config
370+ items:
371+ - key: main-config
372+ path: my-custom.cnf
373+ - name: mysql-data
374+ persistentVolumeClaim:
375+ claimName: mysql-volume-claim
376+---
377+apiVersion: v1
378+kind: Service
379+metadata:
380+ name: mysql-service
381+spec:
382+ type: NodePort
383+ selector:
384+ app: mysql
385+ ports:
386+ - protocol: TCP
387+ port: 3306
388+ targetPort: 3306
389+ nodePort: 30306
390+ name: mysql

Subscribers

People subscribed via source and target branches

to all changes: