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
diff --git a/HACKING.md b/HACKING.md
0new file mode 1006440new file mode 100644
index 0000000..662c988
--- /dev/null
+++ b/HACKING.md
@@ -0,0 +1,14 @@
1# Contributing
2
3In order to contribute to the MySQL OCI image do the following:
4
5* Create a new branch.
6* Make your changes. Keep your commits logically separated. If it is fixing a bug do not forget to mention it in the commit message.
7* Build a new image with your changes. You can use the following command:
8
9```
10$ docker build -t squeakywheel/mysql:test -f Dockerfile .
11```
12
13* Test the new image. Run it in some way that exercises your changes, you can also check th README.md file.
14* If everything goes well submit a merge proposal.
diff --git a/README.md b/README.md
index 7056b37..4a45fdb 100644
--- a/README.md
+++ b/README.md
@@ -1,14 +1,199 @@
1## Ubuntu MySQL 8.0 OCI image1# MySQL | Ubuntu
22
3This is a fork of upstream's mysql image from https://github.com/docker-library/mysql3## About MySQL
44
5These are the main changes:5MySQL is a fast, stable and true multi-user, multi-threaded SQL database
6- using Ubuntu Focal 20.04 LTS as the layer6server. SQL (Structured Query Language) is the most popular database query
7- installing MySQL 8.0 from Ubuntu Focal 12.04 LTS7language in the world. The main goals of MySQL are speed, robustness and ease
8- amd64 only at the moment8of use.
99
10The entrypoint and environment variables were not changed.10## Tags
1111
12Bugs? Comments? Get in touch with the Ubuntu Server team at12- `8.0.22-focal`, `8.0.22`, `8.0-focal`, `8.0``8-focal`, `8`, `focal`, `beta` - **/!\ this is a beta release**
13https://discourse.ubuntu.com/c/server/
1413
14### Architectures supported
15
16- `amd64`, `arm64`, `s390x`
17
18## Usage
19
20### Docker CLI
21
22```sh
23$ docker network create mysql-net
24# Run the server
25$ docker run --name mysql-instance --network mysql-net --env MYSQL_ROOT_PASSWORD=My$seCret --detach squeakywheel/mysql:edge
26# Run the client
27$ docker run --interactive --tty --rm --network mysql-net squeakywheel/mysql:edge mysql -hmysql-instance -Uroot -p
28```
29
30The password will be asked and you can enter `My$seCret`. Now, you are logged in and can enjoy your new instance.
31
32Since 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:
33
34```sh
35$ docker run --name mysql --volume /path/to/persisted/data:/var/lib/mysql --env MYSQL_RANDOM_ROOT_PASSWORD squeakywheel/mysql:edge
36```
37
38#### Parameters
39
40| Parameter | Description |
41|---|---|
42| `-e TZ=UTC` | Timezone |
43| `-e MYSQL_ROOT_PASSWORD=secret_for_root` | Set the password for the `root` user. This option is **mandatory** and **must not be empty**. |
44| `-e MYSQL_PASSWORD=secret` | Set the password for the `MYSQL_USER` user. |
45| `-e MYSQL_USER=john` | Create a new user with superuser privileges. This is used in conjunction with `MYSQL_PASSWORD` |
46| `-e MYSQL_DATABASE=db_test` | Set the name of the default database. |
47| `-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**. |
48| `-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`. |
49| `-e MYSQL_ONETIME_PASSWORD=yes` | Set `root` user as experide once initialization is complete, forcing a password change on first login. |
50| `-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. |
51
52#### Initialization Scripts
53
54One 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:
55
56* Run any `*.sql` files in alphabetically order. By default the target database is specified via `MYSQL_DATABASE`.
57* Run any executable `*.sh` scripts in alphabetically order.
58* Source any non-executable `*.sh` scripts in alphabetically order.
59
60All 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.
61
62#### Database Configuration
63
64You can pass your own configuration files to the container doing the following:
65
66```sh
67$ docker run --name mysql --volume /path/to/mysql/config/files/:/etc/mysql/mysql.conf.d/ --env MYSQL_ROOT_PASSWORD=P@sSwd squeakywheel/mysql:edge
68```
69
70#### Debugging
71
72In 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:
73
74```sh
75$ docker exec -it <name_of_the_container> /bin/bash
76```
77
78To see how to use the MySQL OCI image with `docker-compose` and `kubernetes` check the `examples/README.md` file.
79
80## Deploy with Kubernetes
81
82You can use your favorite Kubernetes distribution; if you don't have one, consider [installing MicroK8s](https://microk8s.io/).
83
84With microk8s running, enable the `dns` and `storage` add-ons:
85```sh
86$ microk8s enable dns storage
87 ```
88
89Create 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)):
90
91```sh
92$ microk8s kubectl create configmap mysql-config --from-file=main-config=config/my-custom.cnf
93```
94
95Use the sample deployment yaml provided [here](https://git.launchpad.net/~canonical-server/ubuntu-server-oci/+git/mysql/plain/examples/mysql-deployment.yml).
96
97<details>
98 <summary>Apply the `mysql-deployment.yml` (click to expand)</summary>
99
100```yaml
101# mysql-deployment.yml
102---
103apiVersion: v1
104kind: PersistentVolumeClaim
105metadata:
106 name: mysql-volume-claim
107spec:
108 accessModes:
109 - ReadWriteOnce
110 storageClassName: microk8s-hostpath
111 resources:
112 requests:
113 storage: 500M
114---
115apiVersion: apps/v1
116kind: Deployment
117metadata:
118 name: mysql-deployment
119spec:
120 replicas: 1
121 selector:
122 matchLabels:
123 app: mysql
124 template:
125 metadata:
126 labels:
127 app: mysql
128 spec:
129 containers:
130 - name: mysql
131 image: squeakywheel/mysql:edge
132 env:
133 - name: MYSQL_RANDOM_ROOT_PASSWORD
134 value: "yes"
135 - name: MYSQL_PASSWORD
136 value: "myS&cret"
137 - name: MYSQL_USER
138 value: "john"
139 volumeMounts:
140 - name: mysql-config-volume
141 mountPath: /etc/mysql/mysql.conf.d/my-custom.cnf
142 subPath: my-custom.cnf
143 - name: mysql-data
144 mountPath: /var/lib/mysql
145 ports:
146 - containerPort: 3306
147 name: mysql
148 protocol: TCP
149 volumes:
150 - name: mysql-config-volume
151 configMap:
152 name: mysql-config
153 items:
154 - key: main-config
155 path: my-custom.cnf
156 - name: mysql-data
157 persistentVolumeClaim:
158 claimName: mysql-volume-claim
159---
160apiVersion: v1
161kind: Service
162metadata:
163 name: mysql-service
164spec:
165 type: NodePort
166 selector:
167 app: mysql
168 ports:
169 - protocol: TCP
170 port: 3306
171 targetPort: 3306
172 nodePort: 30306
173 name: mysql
174```
175
176</details>
177
178```sh
179$ microk8s kubectl apply -f mysql-deployment.yml
180```
181
182You will now be able to connect to the MySQL server on `localhost:30306`.
183
184## Bugs and Features request
185
186If you find a bug in our image or want to request a specific feature file a bug here:
187
188https://bugs.launchpad.net/ubuntu-server-oci/+filebug
189
190In the title of the bug add `mysql: <reason>`.
191
192Make sure to include:
193
194* 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:
195```sh
196$ docker images --no-trunc --quiet squeakywheel/mysql:<tag>
197```
198* Reproduction steps for the deployment
199* If it is a feature request, please provide as much detail as possible
diff --git a/examples/README.md b/examples/README.md
15new file mode 100644200new file mode 100644
index 0000000..b07a46b
--- /dev/null
+++ b/examples/README.md
@@ -0,0 +1,44 @@
1# Running the examples
2
3## docker-compose
4
5Install `docker-compose` from the Ubuntu archive:
6
7```
8$ sudo apt install -y docker-compose
9```
10
11Call `docker-compose` from the examples directory:
12
13```
14$ docker-compose up -d
15```
16
17MySQL 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:
18
19```
20$ docker-compose down
21```
22
23# Microk8s
24
25With microk8s running, enable the `dns` and `storage` add-ons:
26
27```
28$ microk8s enable dns storage
29```
30
31Create a configmap for the configuration files:
32
33```
34$ microk8s kubectl create configmap mysql-config \
35 --from-file=main-config=config/my-custom.cnf
36```
37
38Apply the `mysql-deployment.yml`:
39
40```
41$ microk8s kubectl apply -f mysql-deployment.yml
42```
43
44MySQL will be running and available via port `30306` on your host. The password of the `john` user will be `myS&cret`.
diff --git a/examples/config/my-custom.cnf b/examples/config/my-custom.cnf
0new file mode 10064445new file mode 100644
index 0000000..8e55230
--- /dev/null
+++ b/examples/config/my-custom.cnf
@@ -0,0 +1,3 @@
1[mysqld]
2bind-address = 0.0.0.0
3port = 3306
diff --git a/examples/docker-compose.yml b/examples/docker-compose.yml
0new file mode 1006444new file mode 100644
index 0000000..ec0ea8f
--- /dev/null
+++ b/examples/docker-compose.yml
@@ -0,0 +1,14 @@
1version: '2'
2
3services:
4 mysql:
5 image: squeakywheel/mysql:edge
6 network_mode: "host"
7 ports:
8 - 3306:3306
9 environment:
10 - MYSQL_RANDOM_ROOT_PASSWORD=yes
11 - MYSQL_PASSWORD=myS&cret
12 - MYSQL_USER=john
13 volumes:
14 - ./config/my-custom.cnf:/etc/mysql/mysql.conf.d/my-custom.cnf
diff --git a/examples/mysql-deployment.yml b/examples/mysql-deployment.yml
0new file mode 10064415new file mode 100644
index 0000000..2a30022
--- /dev/null
+++ b/examples/mysql-deployment.yml
@@ -0,0 +1,72 @@
1---
2apiVersion: v1
3kind: PersistentVolumeClaim
4metadata:
5 name: mysql-volume-claim
6spec:
7 accessModes:
8 - ReadWriteOnce
9 storageClassName: microk8s-hostpath
10 resources:
11 requests:
12 storage: 500M
13---
14apiVersion: apps/v1
15kind: Deployment
16metadata:
17 name: mysql-deployment
18spec:
19 replicas: 1
20 selector:
21 matchLabels:
22 app: mysql
23 template:
24 metadata:
25 labels:
26 app: mysql
27 spec:
28 containers:
29 - name: mysql
30 image: squeakywheel/mysql:edge
31 env:
32 - name: MYSQL_RANDOM_ROOT_PASSWORD
33 value: "yes"
34 - name: MYSQL_PASSWORD
35 value: "myS&cret"
36 - name: MYSQL_USER
37 value: "john"
38 volumeMounts:
39 - name: mysql-config-volume
40 mountPath: /etc/mysql/mysql.conf.d/my-custom.cnf
41 subPath: my-custom.cnf
42 - name: mysql-data
43 mountPath: /var/lib/mysql
44 ports:
45 - containerPort: 3306
46 name: mysql
47 protocol: TCP
48 volumes:
49 - name: mysql-config-volume
50 configMap:
51 name: mysql-config
52 items:
53 - key: main-config
54 path: my-custom.cnf
55 - name: mysql-data
56 persistentVolumeClaim:
57 claimName: mysql-volume-claim
58---
59apiVersion: v1
60kind: Service
61metadata:
62 name: mysql-service
63spec:
64 type: NodePort
65 selector:
66 app: mysql
67 ports:
68 - protocol: TCP
69 port: 3306
70 targetPort: 3306
71 nodePort: 30306
72 name: mysql

Subscribers

People subscribed via source and target branches

to all changes: