Quick Common Docker Run Commands

A simple cheat sheet for some of the most common docker run commands. Suitable for development environments, but more tinkering is needed if you want to run production-grade containers.
You will need to adjust the values of container names, environment variables, and other information yourself to suit your development needs.
Databases
MySQL
Create a local instance of MySQL, using the mysql:latest image with the following information:
Details
-
Container name:
mysql -
Root user:
root -
Password:
123456 -
Initial database:
mydatabase -
Exposed port:
3306 -
Volume:
mysql-volume
- Windows
- Linux/MacOS
docker run --detach --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=mydatabase -v mysql-volume:/var/lib/mysql mysql:latest
docker run \
--detach \
--name mysql \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=123456 \
-e MYSQL_DATABASE=mydatabase \
-v mysql-volume:/var/lib/mysql \
mysql:latest
MariaDB
Create a local instance of MariaDB, using the mariadb:lts image, with the following information:
Details
-
Container name:
mariadb -
Root user:
root -
Password:
123456 -
Initial database:
mydatabase -
Exposed port:
3306 -
Volume:
mariadb-volume
- Windows
- Linux/MacOS
docker run --detach --name mariadb -e MARIADB_ROOT_PASSWORD=123456 -e MARIADB_DATABASE=mydatabase -p 3306:3306 -v mariadb-volume:/var/lib/mysql mariadb:lts
docker run \
--detach \
--name mariadb \
-e MARIADB_ROOT_PASSWORD=123456 \
-e MARIADB_DATABASE=mydatabase \
-p 3306:3306 \
-v mariadb-volume:/var/lib/mysql \
mariadb:lts
SQL Server
Create a local instance of Microsoft SQL Server, using the mcr.microsoft.com/mssql/server:2025-latest image, with the following information:
Details
SQL Server requires complex password usage, so we cannot use the simple 123456 as our default SA password.
-
Container name:
sqlserver -
Root user:
sa -
Password:
123456Aa@ -
Initial database:
master -
Exposed port:
1433 -
Volume:
sqlserver-volume
- Windows
- Linux/MacOS
docker run --detach -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=123456Aa@" -e "MSSQL_PID=Evaluation" -p 1433:1433 --name sqlserver --hostname sqlserver -v sqlserver-volume:/var/opt/mssql mcr.microsoft.com/mssql/server:2025-latest
docker run \
--detach \
--name sqlserver \
--hostname sqlserver \
-e "ACCEPT_EULA=Y" \
-e "MSSQL_SA_PASSWORD=123456Aa@" \
-e "MSSQL_PID=Evaluation" \
-p 1433:1433 \
-v sqlserver-volume:/var/opt/mssql \
mcr.microsoft.com/mssql/server:2025-latest
PostgreSQL
Create a local instance of PostgreSQL, using the postgres:alpine image, with the following information:
Details
-
Container name:
postgresql -
Root user:
postgres -
Password:
123456 -
Initial database:
mydatabase -
Exposed port:
5432 -
Volume:
postgresql-volume
- Windows
- Linux/MacOS
docker run --detach --name postgresql -e "POSTGRES_USER=postgres" -e "POSTGRES_PASSWORD=123456" -e "POSTGRES_DB=mydatabase" -p 5432:5432 -v postgresql-volume:/var/lib/postgresql/data postgres:alpine
docker run \
--detach \
--name postgresql \
-e "POSTGRES_USER=postgres" \
-e "POSTGRES_PASSWORD=123456" \
-e "POSTGRES_DB=mydatabase" \
-p 5432:5432 \
-v postgresql-volume:/var/lib/postgresql/data \
postgres:alpine
Oracle Database
Create a local instance of Oracle Database, using the gvenzl/oracle-free:slim-faststart image, with the following information:
Details
-
Container name:
oracledb -
Root user:
SYSTEM -
Password:
123456 -
Default schema:
FREE -
Exposed port:
1521 -
Volume:
oracledb-volume
- Windows
- Linux/MacOS
docker run --detach --name oracledb -e "ORACLE_PASSWORD=123456" -v oracledb-volume:/opt/oracle/oradata -p 1521:1521 gvenzl/oracle-free:slim-faststart
docker run \
--detach \
--name oracledb \
-e "ORACLE_PASSWORD=123456" \
-v oracledb-volume:/opt/oracle/oradata \
-p 1521:1521 \
gvenzl/oracle-free:slim-faststart
Message Queues/Brokers
Apache Kafka (Without Zookeeper)
Create a local instance of Apache Kafka, using the bashj79/kafka-kraft:latest image, with the following information:
Details
-
Container name:
kafka -
Exposed port:
9092
- Windows
- Linux/MacOS
docker run --detach --name kafka -p 9092:9092 bashj79/kafka-kraft
docker run \
--detach \
--name kafka \
-p 9092:9092 \
bashj79/kafka-kraft
RabbitMQ
Create a local instance of RabbitMQ, using the rabbitmq:alpine image, with the following information:
Details
-
Container name:
rabbitmq -
Host name:
rabbitmq-host -
Username:
rabbitmq -
Password:
123456 -
Exposed ports:
5672and15672(bind to8080)
- Windows
- Linux/MacOS
docker run --detach --name rabbitmq --hostname rabbitmq-host -e RABBITMQ_DEFAULT_USER=rabbitmq -e RABBITMQ_DEFAULT_PASS=123456 -p 5672:5672 -p 8080:15672 rabbitmq:alpine
docker run \
--detach \
--name rabbitmq \
--hostname rabbitmq-host \
-e RABBITMQ_DEFAULT_USER=rabbitmq \
-e RABBITMQ_DEFAULT_PASS=123456 \
-p 5672:5672 \
-p 8080:15672 \
rabbitmq:alpine
Redis
Create a local instance of Redis, using the redis:alpine image, with the following information:
Details
-
Container name:
redis -
Exposed port:
6379 -
Password:
123456(useredis-cliand typeauth 123456to access Redis on the command line interface) -
Volume:
redis-volume
- Windows
- Linux/MacOS
docker run --detach --name redis -v redis-volume:/data -p 6379:6379 redis:alpine redis-server --requirepass 123456 --save 60 1 --loglevel warning
docker run \
--detach \
--name redis \
-v redis-volume:/data \
-p 6379:6379 \
redis:alpine \
redis-server --requirepass 123456 --save 60 1 --loglevel warning
Keycloak
Without External Database
Create a local instance of Keycloak, using the quay.io/keycloak/keycloak:latest image, with the following information:
Details
-
Container name:
keycloak -
Credentials:
-
Admin username:
admin -
Admin password:
123456 -
Visit
localhost:8080and useadmin/123456as username and password to log in
-
- Exposed ports:
8080and9000(for health check and metrics)
- Windows
- Linux/MacOS
docker run --name keycloak --detach -p 8080:8080 -p 9000:9000 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=123456 -e KC_HEALTH_ENABLED=true -e KC_METRICS_ENABLED=true quay.io/keycloak/keycloak:latest start-dev
docker run \
--name keycloak \
--detach \
-p 8080:8080 \
-p 9000:9000 \
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
-e KC_BOOTSTRAP_ADMIN_PASSWORD=123456 \
-e KC_HEALTH_ENABLED=true \
-e KC_METRICS_ENABLED=true \
quay.io/keycloak/keycloak:latest \
start-dev
With External Database
With an external database, you need additional environment variables:
Details
-
KC_DB: The vendor of the external database. Supported values aremariadb(MariaDB),mssql(SQL Server),mysql(MySQL),oracle(Oracle Database), andpostgres(PostgreSQL). -
KC_DB_URL_HOST: The hostname of the chosen database vendor -
KC_DB_URL_PORT: The port number of the chosen database vendor (by default,3306for MySQL/MariaDB,1433for SQL Server,5432for PostgreSQL, and1521for Oracle Database) -
KC_DB_DATABASE: The database schema to be used. Sometimes you need to provideKC_DB_SCHEMAas well. -
KC_DB_USERNAME: The username -
KC_DB_PASSWORD: The password
Example
Suppose you want to connect to an external PostgreSQL database (often on the same network) with the hostname postgres and credentials keycloak/123456. This will be your new docker run command:
- Windows
- Linux/MacOS
docker run --name keycloak --detach -p 8080:8080 -p 9000:9000 -e KC_BOOTSTRAP_ADMIN_USERNAME=admin -e KC_BOOTSTRAP_ADMIN_PASSWORD=123456 -e KC_HEALTH_ENABLED=true -e KC_METRICS_ENABLED=true -e KC_DB=postgres -e KC_DB_URL_HOST=postgres -e KC_DB_URL_PORT=5432 -e KC_DB_DATABASE=keycloak -e KC_DB_USERNAME=keycloak -e KC_DB_PASSWORD=123456 quay.io/keycloak/keycloak:latest start-dev
docker run \
--name keycloak \
--detach \
-p 8080:8080 \
-p 9000:9000 \
-e KC_BOOTSTRAP_ADMIN_USERNAME=admin \
-e KC_BOOTSTRAP_ADMIN_PASSWORD=123456 \
-e KC_HEALTH_ENABLED=true \
-e KC_METRICS_ENABLED=true \
-e KC_DB=postgres \
-e KC_DB_URL_HOST=postgres \
-e KC_DB_URL_PORT=5432 \
-e KC_DB_DATABASE=keycloak \
-e KC_DB_USERNAME=keycloak \
-e KC_DB_PASSWORD=123456 \
quay.io/keycloak/keycloak:latest \
start-dev
You can see this demo repository for better usage of Keycloak with external PostgreSQL.
Docker Compose for Quick-Start Testing
If you want to create a Keycloak composition bundled with an external PostgreSQL database as the datasource (with persistent volume), consider creating a docker-compose.yaml file like this:
Details
services:
postgresql:
container_name: postgresql
image: postgres:alpine
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: 123456
POSTGRES_DB: keycloak
ports:
- "5432:5432"
volumes:
- postgresql-volume:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
networks:
- keycloak-network
keycloak:
container_name: keycloak
image: quay.io/keycloak/keycloak:latest
command: start-dev
environment:
KC_BOOTSTRAP_ADMIN_USERNAME: admin
KC_BOOTSTRAP_ADMIN_PASSWORD: 123456
KC_HEALTH_ENABLED: true
KC_METRICS_ENABLED: true
KC_DB: postgres
KC_DB_URL_HOST: postgresql
KC_DB_URL_PORT: 5432
KC_DB_DATABASE: keycloak
KC_DB_USERNAME: postgres
KC_DB_PASSWORD: 123456
ports:
- "8080:8080"
- "9000:9000"
depends_on:
postgresql:
condition: service_healthy
networks:
- keycloak-network
volumes:
postgresql-volume:
networks:
keycloak-network:
driver: bridge
This configuration starts a composition of two containers: one for Keycloak and another for the PostgreSQL instance. It includes a health check for PostgreSQL to ensure that Keycloak only starts when the database is fully operational.
Connection info (the same as ones defined in the section above):
-
Container name:
keycloak -
Credentials:
-
Admin username:
admin -
Admin password:
123456
-
-
Exposed ports:
8080and9000 (for health check and metrics) -
Visit
localhost:8080and useadmin/123456as username and password to log in
You can check this sample repository for a complete guide on how to start a Keycloak container bundled with a support PostgreSQL instance.
MinIO
MinIO is now source distributed only (meaning no more Docker image update).
I will be working on alternative options for MinIO as S3-compatible object storage services.
Elasticsearch
https://www.elastic.co/docs/deploy-manage/deploy/self-managed/install-elasticsearch-docker-basic
Create a local instance of Elasticsearch, using the docker.elastic.co/elasticsearch/elasticsearch-wolfi:9.1.5 image, with the following information:
Details
-
Container name:
elasticsearch -
Exposed ports:
9200and9300 -
Volume:
elasticsearc-volume -
Credentials: either no credentials, or
elastic/123456(see the command line below) -
Limiting memory usage to 2 GB
- Windows
- Linux/MacOS
With credentials:
docker run --name elasticsearch --detach -e "xpack.security.enabled=true" -e "discovery.type=single-node" -e "ELASTIC_PASSWORD=123456" -p 9200:9200 -p 9300:9300 -m 2GB -v elasticsearch-volume:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch-wolfi:9.1.5
Without credentials:
docker run --name elasticsearch --detach -e "xpack.security.enabled=false" -e "discovery.type=single-node" -p 9200:9200 -p 9300:9300 -m 2GB -v elasticsearch-volume:/usr/share/elasticsearch/data docker.elastic.co/elasticsearch/elasticsearch-wolfi:9.1.5
With credentials:
docker run \
--name elasticsearch \
--detach \
-e "xpack.security.enabled=true" \
-e "discovery.type=single-node" \
-e "ELASTIC_PASSWORD=123456" \
-p 9200:9200 \
-p 9300:9300 \
-m 2GB \
-v elasticsearch-volume:/usr/share/elasticsearch/data \
docker.elastic.co/elasticsearch/elasticsearch-wolfi:9.1.5
Without credentials:
docker run \
--name elasticsearch \
--detach \
-e "xpack.security.enabled=false" \
-e "discovery.type=single-node" \
-p 9200:9200 \
-p 9300:9300 \
-m 2GB \
-v elasticsearch-volume:/usr/share/elasticsearch/data \
docker.elastic.co/elasticsearch/elasticsearch-wolfi:9.1.5
(to be updated)