Skip to content

docs: update readme from mariadb with port binding, tags, remove double spaces and informations #2552

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
28 changes: 19 additions & 9 deletions mariadb/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,38 +12,48 @@ The %%IMAGE%% has a number of tags, and of note is `latest`, as the latest stabl

## Running the container

### Configuration

#### Port binding

By default, the database running within the container will listen on port 3306. You can expose the container port 3306 to the host port 3306 with the `-p 3306:3306` argument to `docker run`, like the command below:

```console
$ docker run --name some-%%REPO%% -p 3306:3306 %%IMAGE%%:latest
```

### Starting using a minimal configuration

The environment variables required to use this image involves the setting of the root user password:

```console
$ docker run --detach --name some-%%REPO%% --env MARIADB_ROOT_PASSWORD=my-secret-pw %%IMAGE%%:latest
$ docker run --detach --name some-%%REPO%% --env MARIADB_ROOT_PASSWORD=my-secret-pw %%IMAGE%%:latest
```

or:

```console
$ docker run --detach --name some-%%REPO%% --env MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 %%IMAGE%%:latest
$ docker run --detach --name some-%%REPO%% --env MARIADB_ALLOW_EMPTY_ROOT_PASSWORD=1 %%IMAGE%%:latest
```

or:

```console
$ docker run --detach --name some-%%REPO%% --env MARIADB_RANDOM_ROOT_PASSWORD=1 %%IMAGE%%:latest
$ docker run --detach --name some-%%REPO%% --env MARIADB_RANDOM_ROOT_PASSWORD=1 %%IMAGE%%:latest
```

... where the container logs will contain the generated root password.

## %%STACK%%
## %%Docker Compose%%

Run `docker stack deploy -c stack.yml %%REPO%%` (or `docker-compose -f stack.yml up`), wait for it to initialize completely, and visit `http://swarm-ip:8080`, `http://localhost:8080`, or `http://host-ip:8080` (as appropriate).
Run `docker compose -f stack.yml up`, wait for it to initialize completely, and visit `http://localhost:8080`, or `http://host-ip:8080` (as appropriate).

### Start a `%%IMAGE%%` server instance with user, password and database

Starting a MariaDB instance with a user, password, and a database:

```console
$ docker run --detach --name some-%%REPO%% --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_DATABASE=exmple-database --env MARIADB_ROOT_PASSWORD=my-secret-pw %%IMAGE%%:latest
$ docker run --detach --name some-%%REPO%% --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_DATABASE=exmple-database --env MARIADB_ROOT_PASSWORD=my-secret-pw %%IMAGE%%:latest
```

### Start a `%%IMAGE%%` server instance in a network
Expand All @@ -52,8 +62,8 @@ As applications talk to MariaDB, MariaDB needs to start in the same network as t

```console
$ docker network create some-network
$ docker run --detach --network some-network --name some-%%REPO%% --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_ROOT_PASSWORD=my-secret-pw %%IMAGE%%:latest
$ docker run --detach --network some-network --name some-application --env APP_DB_HOST=some-%%REPO%% --env APP_DB_USER=example-user --env APP_DB_PASSWD=my_cool_secret some-application
$ docker run --detach --network some-network --name some-%%REPO%% --env MARIADB_USER=example-user --env MARIADB_PASSWORD=my_cool_secret --env MARIADB_ROOT_PASSWORD=my-secret-pw %%IMAGE%%:latest
$ docker run --detach --network some-network --name some-application --env APP_DB_HOST=some-%%REPO%% --env APP_DB_USER=example-user --env APP_DB_PASSWD=my_cool_secret some-application
```

... where `some-network` is a newly created network (other than `bridge` as the default network), `some-%%REPO%%` is the name you want to assign to your container, `my-secret-pw` is the password to be set for the MariaDB root user. See the list above for relevant tags to match your needs and environment. `some-application` and then environment variable `APP_DB_HOST`, `APP_DB_USER` and `APP_DB_PASSWD` are the application's configuration for its database connection.
Expand All @@ -63,7 +73,7 @@ $ docker run --detach --network some-network --name some-application --env APP_D
The following command starts another `%%IMAGE%%` container instance and runs the `mariadb` command line client against your original `%%IMAGE%%` container, allowing you to execute SQL statements against your database instance:

```console
$ docker run -it --network some-network --rm %%IMAGE%% mariadb -hsome-%%REPO%% -uexample-user -p
$ docker run -it --network some-network --rm %%IMAGE%% mariadb -h some-%%REPO%% -u example-user
```

... where `some-%%REPO%%` is the name of your original `%%IMAGE%%` container (connected to the `some-network` Docker network).
Expand Down
5 changes: 2 additions & 3 deletions mariadb/stack.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
# Use root/example as user/password credentials
version: '3.1'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we drop this, we also need to drop the references to docker stack deploy; see also #2516 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we drop this, we also need to drop the references to docker stack deploy; see also #2516 (comment)

https://docs.docker.com/reference/compose-file/version-and-name/#version-top-level-element-obsolete

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more explicitly:

https://docs.docker.com/engine/swarm/stack-deploy "The docker stack deploy command uses the legacy Compose file version 3 format, used by Compose V1"

https://docs.docker.com/compose/intro/history/ " (from image - Compose V1 / Compose file version - "Used version top level element". So if you remove version, remove the docker stack deploy like @tianon said.


services:

db:
image: mariadb
image: mariadb:latest
restart: always
environment:
MARIADB_ROOT_PASSWORD: example

adminer:
image: adminer
image: adminer:latest
restart: always
ports:
- 8080:8080