Simplify docker networking and clarify the README, fixes #8

This commit is contained in:
Felix Albrigtsen 2024-07-12 21:27:15 +02:00
parent 34dfc562a9
commit 1a5dc96f0d
2 changed files with 10 additions and 5 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/target /target
config.toml

View File

@ -15,17 +15,21 @@ Ensure you have a [rust toolchain](https://www.rust-lang.org/tools/install) inst
In order to set up a test instance of mariadb in a docker container, run the following command: In order to set up a test instance of mariadb in a docker container, run the following command:
```bash ```bash
docker run --rm --name mariadb -e MYSQL_ROOT_PASSWORD=secret -d mariadb:latest docker run --rm --name mariadb -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 -d mariadb:latest
``` ```
You should then create a config file, and adjust the hostname to the IP address of the docker container. This will start a mariadb instance with the root password `secret`, and expose the port 3306 on the host machine.
Run the following command to create a configuration file with the default settings:
```bash ```bash
cp ./example-config.toml ./config.toml cp ./example-config.toml ./config.toml
DOCKER_IP_ADDRESS="$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mariadb)"
sed -i "s/host = \"localhost\"/host = \"${DOCKER_IP_ADDRESS}\"/" ./config.toml
``` ```
If you used the docker command above, you can use these settings as is, but if you are running mariadb/mysql on another host, port or with another password, adjust the corresponding fields in `config.toml`.
This file will contain your database password, but is ignored by git, so it will not be committed to the repository.
You should now be able to connect to the mariadb instance, after building the program and using arguments to specify the config file. You should now be able to connect to the mariadb instance, after building the program and using arguments to specify the config file.
```bash ```bash
@ -42,4 +46,4 @@ To stop and remove the container, run the following command:
```bash ```bash
docker stop mariadb docker stop mariadb
``` ```