Accéder au contenu principal

Docker Cheat Sheet for Common Database Engine

I use docker almost everyday, and usually everything is already set-up in the project.

But from time to time I need one or a few tools to do something. For example, when I contribute to a project that require a Database, I need a PostgreSQL container. Or sometime I need to explore some data and I need Elasticsearch or Grafana.

In this short blog post, I’ll share with you some containers I use.

Section intitulée table-of-contentsTable of contents

Section intitulée networkNetwork

Some containers need a network to talk to each other (like Elasticsearch & Kibana or InfluxDB & Grafana). To keep it simple, I put all containers in the same tools network.

docker network create tools

If you forget to select a network when starting a container, you can connect it later with:

docker network connect tools grafana

Section intitulée containerContainer

Almost all tools write data on disk. And I don’t want to lose theses data if I drop a container. So I create a named volume for each one.

If you don’t remember where to mount the volume, you can use the following command to find it:

$ docker inspect mysql:8 --format '{{ .Config.Volumes }}'
map[/var/lib/mysql:{}]

In this case, the volume must be mounted to /var/lib/mysql.

I also bind the default port of the container to the host, it eases the interaction with other tools on my host.

Section intitulée how-to-start-a-postgresql-18-x-docker-containerHow to start a PostgreSQL 18.x docker container

docker run -d --name=postgres18 \
    -v postgres18:/var/lib/postgresql \
    --network tools -p 5432:5432 \
    -e POSTGRES_PASSWORD=app \
    -e POSTGRES_USER=app \
    postgres:18

Then from your host:

PGPASSWORD=app psql -h 127.0.0.1 -U app

Or you can enter into the container directly:

docker exec -it postgres18 psql -U app

Section intitulée how-to-start-a-mariadb-docker-containerHow to start a MariaDB docker container

MariaDB has its own versioning: 11.x is the current LTS, 12.x is the latest short-term release.

docker run -d --name mariadb12 \
    -v mariadb12:/var/lib/mysql \
    --network tools \
    -p 3306:3306 \
    -e MARIADB_ROOT_PASSWORD=password \
    mariadb:12

Then from your host:

mysql -h127.0.0.1 -uroot -ppassword

Or you can enter into the container directly:

docker exec -it mariadb12 mariadb -uroot -ppassword

Section intitulée how-to-start-a-mysql-docker-containerHow to start a MySQL docker container

Oracle now ships two tracks: the 8.4 LTS release and the 9.x Innovation release (currently 9.7). Pick whichever matches your production target, they use the same image and options.

docker run -d --name mysql9 \
    -v mysql9:/var/lib/mysql \
    --network tools \
    -p 3306:3306 \
    -e MYSQL_ROOT_PASSWORD=password \
    mysql:9

Then from your host:

mysql -h127.0.0.1 -uroot -ppassword

Or you can enter into the container directly:

docker exec -it mysql9 mysql -uroot -ppassword

Section intitulée how-to-start-a-redis-8-x-docker-containerHow to start a Redis 8.x docker container

Since Redis 8, the Redis Stack and community offerings have been merged back into a single Redis Open Source distribution (AGPLv3).

docker run -d --name redis8 \
    -v redis8:/data \
    --network tools \
    -p 6379:6379 \
    redis:8

Then from your host:

redis-cli

Or you can enter into the container directly:

docker exec -it redis8 redis-cli

Section intitulée how-to-start-a-redisinsight-docker-containerHow to start a RedisInsight docker container

A web UI to browse keys, run commands and profile a Redis (or Valkey) instance. Since it’s on the tools network, add redis8 (the container name) as host when connecting from the UI.

docker run -d --name redisinsight \
    -v redisinsight:/data \
    --network tools \
    -p 5540:5540 \
    redis/redisinsight:3.6

Then you can open http://127.0.0.1:5540/

Section intitulée how-to-start-a-valkey-docker-containerHow to start a Valkey docker container

Valkey is the Linux Foundation fork of Redis, created after Redis dropped its open-source license (before it went back to AGPLv3 with Redis 8). It’s a drop-in replacement, same protocol and CLI.

docker run -d --name valkey9 \
    -v valkey9:/data \
    --network tools \
    -p 6380:6379 \
    valkey/valkey:9

Then from your host:

redis-cli -p 6380

Or you can enter into the container directly:

docker exec -it valkey9 valkey-cli

Section intitulée how-to-start-a-mongodb-docker-containerHow to start a MongoDB docker container

docker run -d --name mongo8 \
    -v mongo8:/data/db \
    --network tools \
    -p 27017:27017 \
    -e MONGO_INITDB_ROOT_USERNAME=app \
    -e MONGO_INITDB_ROOT_PASSWORD=app \
    mongo:8

Then from your host:

mongosh "mongodb://app:app@127.0.0.1:27017/"

Or you can enter into the container directly:

docker exec -it mongo8 mongosh -u app -p app

Section intitulée how-to-start-a-clickhouse-docker-containerHow to start a ClickHouse docker container

Columnar analytical database, great for crunching large volumes of logs or metrics with SQL. The default user has no password out of the box.

docker run -d --name clickhouse26 \
    -v clickhouse26:/var/lib/clickhouse \
    --network tools \
    -p 8123:8123 \
    -p 9000:9000 \
    --ulimit nofile=262144:262144 \
    clickhouse/clickhouse-server:26.6

Then from your host:

clickhouse-client --host 127.0.0.1

Or you can enter into the container directly:

docker exec -it clickhouse26 clickhouse-client

Section intitulée how-to-start-a-rabbitmq-4-x-docker-containerHow to start a RabbitMQ 4.x docker container

docker run -d --name rabbitmq4 -v rabbitmq4:/var/lib/rabbitmq --network tools -p 5672:5672 -p 15672:15672 rabbitmq:4-management

Then you can open http://127.0.0.1:15672/

Section intitulée how-to-start-an-influxdb-3-core-docker-containerHow to start an InfluxDB 3 Core docker container

InfluxDB 3 is a full rewrite (in Rust) and replaces the old influx CLI with influxdb3. It also requires an explicit data directory and, since 3.x, an auth token to create databases.

The image runs as the non-root influxdb3 user (uid/gid 1500), but a fresh named volume is created owned by root. So the very first time, fix the ownership before starting the server, otherwise it crashes with a PermissionDenied error:

docker run --rm --user root -v influxdb3:/var/lib/influxdb3/data influxdb:3-core chown -R 1500:1500 /var/lib/influxdb3/data
docker run -d --name influxdb3 \
    -v influxdb3:/var/lib/influxdb3/data \
    --network tools \
    -p 8181:8181 \
    influxdb:3-core influxdb3 serve \
        --node-id=influxdb3 \
        --object-store=file \
        --data-dir=/var/lib/influxdb3/data

The API is available at http://127.0.0.1:8181/

You first need an admin token, then you can create your database with it:

docker exec influxdb3 influxdb3 create token --admin
docker exec influxdb3 influxdb3 create database stats --token YOUR_AUTH_TOKEN

Then you can query it:

docker exec -it influxdb3 influxdb3 query --database stats --token YOUR_AUTH_TOKEN "SELECT 1"

Section intitulée how-to-start-a-grafana-oss-docker-containerHow to start a Grafana (OSS) docker container

docker run -d --name grafana -v grafana:/var/lib/grafana/ --network tools -p 3000:3000 grafana/grafana-oss

Then you can open http://127.0.0.1:3000/

Section intitulée how-to-start-a-meilisearch-docker-containerHow to start a Meilisearch docker container

A much lighter alternative to Elasticsearch when you just need fast full-text search, with an official Symfony bundle. Without MEILI_MASTER_KEY it starts in dev mode without auth, which is fine for local use.

docker run -d --name meilisearch \
    -v meilisearch:/meili_data \
    --network tools \
    -p 7700:7700 \
    getmeili/meilisearch:v1.49

The API and web UI are available at http://127.0.0.1:7700/

Section intitulée how-to-start-an-elasticsearch-9-x-docker-containerHow to start an Elasticsearch (9.x) docker container

Since Elasticsearch 8, security (TLS + auth) is enabled by default. For a disposable local dev container it’s simpler to turn it off explicitly.

docker run -d --name elasticsearch9 \
    -v elasticsearch9:/usr/share/elasticsearch/data \
    --network tools \
    -p 9200:9200 \
    -e ES_JAVA_OPTS="-Xms1g -Xmx1g" \
    -e "discovery.type=single-node" \
    -e "xpack.security.enabled=false" \
    -e "xpack.security.http.ssl.enabled=false" \
    -e "xpack.security.enrollment.enabled=false" \
    docker.elastic.co/elasticsearch/elasticsearch:9.4.3

The API is available at http://127.0.0.1:9200/

Section intitulée how-to-start-a-kibana-9-x-docker-containerHow to start a Kibana (9.x) docker container

docker run -d --name kibana9 \
    --network tools \
    -p 5601:5601 \
    -e 'ELASTICSEARCH_HOSTS=["http://elasticsearch9:9200"]' \
    docker.elastic.co/kibana/kibana:9.4.3

Then you can open http://127.0.0.1:5601/

Section intitulée stop-startStop / Start

When you don’t need the container anymore, you can stop it with:

docker stop postgres18

And it you need it back:

docker start postgres18

Section intitulée conclusionConclusion

Docker is a very powerful tool, and can help to isolate your development environment. It can also help you to test some product before really integrate them in your favorite stack.

I hope you like this cheat sheet. I’ll keep it updated, so don’t hesitate to bookmark it.

Commentaires et discussions

Ces clients ont profité de notre expertise