Chapter 9. Database Images
9.1. MySQL
9.1.1. Description
The rhscl/mysql-56-rhel7 image provides a MySQL 5.6 SQL database server. The rhscl/mysql-57-rhel7 image provides a MySQL 5.7 SQL database server.
9.1.2. Access and Usage
To pull the rhscl/mysql-56-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/mysql-56-rhel7To pull the rhscl/mysql-57-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/mysql-57-rhel7To set only the mandatory environment variables and not store the database in a host directory, execute the following command:
# docker run -d --name mysql_database -e MYSQL_USER=<user> -e MYSQL_PASSWORD=<pass> \ -e MYSQL_DATABASE=<db> -p 3306:3306 rhscl/mysql-56-rhel7
Change the image name if you are using the rhscl/mysql-57-rhel7 image.
This will create a container named mysql_database running MySQL with database db and user with credentials user:pass. Port 3306 will be exposed and mapped to the host. If you want your database to be persistent across container executions, also add a -v /host/db/path:/var/lib/mysql/data:Z argument. The directory /host/db/path will be the MySQL data directory.
If the database directory is not initialized, the entrypoint script will first run mysql_install_db and set up necessary database users and passwords. After the database is initialized, or if it was already present, mysqld is executed and will run as PID 1. You can stop the detached container by running the docker stop mysql_database command.
9.1.3. Configuration
The image recognizes the following environment variables that you can set during initialization by passing -e VAR=VALUE to the docker run command:
| Variable Name | Description |
|---|---|
|
| User name for MySQL account to be created |
|
| Password for the user account |
|
| Database name |
|
| Password for the root user (optional) |
The root user has no password set by default, only allowing local connections. You can set it by setting the MYSQL_ROOT_PASSWORD environment variable when initializing your container. This will allow you to login to the root account remotely. Local connections will still not require a password.
The following environment variables influence the MySQL configuration file and are all optional:
| Variable name | Description | Default |
|---|---|---|
|
| Sets how the table names are stored and compared | 0 |
|
| The maximum permitted number of simultaneous client connections | 151 |
|
| The maximum size of one packet or any generated/intermediate string | 200M |
|
| The minimum length of the word to be included in a FULLTEXT index | 4 |
|
| The maximum length of the word to be included in a FULLTEXT index | 20 |
|
|
Controls the | 1 |
|
| The number of open tables for all threads | 400 |
|
| The size of the buffer used for index blocks | 32M (or 10% of available memory) |
|
| The size of the buffer used for sorting | 256K |
|
| The size of the buffer used for a sequential scan | 8M (or 5% of available memory) |
|
| The size of the buffer pool where InnoDB caches table and index data | 32M (or 50% of available memory) |
|
| The size of each log file in a log group | 8M (or 15% of available available) |
|
| The size of the buffer that InnoDB uses to write to the log files on disk | 8M (or 15% of available memory) |
|
| Point to an alternative configuration file | /etc/my.cnf |
|
|
Set sets the binlog format, supported values are | statement |
|
|
To enable query logging, set this variable to | 0 |
You can also set the following mount point by passing the -v /host:/container:Z flag to Docker:
| Volume Mount Point | Description |
|---|---|
|
| MySQL data directory |
When mounting a directory from the host into the container, ensure that the mounted directory has the appropriate permissions and that the owner and group of the directory matches the user UID or name which is running inside the container, which is 27 by default.
9.2. MariaDB
9.2.1. Description
The rhscl/mariadb-101-rhel7 image provides a MariaDB 10.1 SQL database server; the rhscl/mariadb-100-rhel7 image provides a MariaDB 10.0 SQL database server.
9.2.2. Access
To pull the rhscl/mariadb-101-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/mariadb-101-rhel7To pull the rhscl/mariadb-100-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/mariadb-100-rhel79.2.3. Usage and Configuration
The usage and configuration is the same as for the MySQL image. For details, see the MySQL section. Note that the name of the daemon is mysqld and all environment variables have the same names as in MySQL. See also How to Extend the rhscl/mariadb-101-rhel7 Container Image.
9.3. PostgreSQL
9.3.1. Description
The rhscl/postgresql-95-rhel7 image provides a PostgreSQL 9.5 SQL database server; the rhscl/postgresql-94-rhel7 image provides a PostgreSQL 9.4 SQL database server.
9.3.2. Access and Usage
To pull the rhscl/postgresql-95-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/postgresql-95-rhel7To pull the rhscl/postgresql-94-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/postgresql-94-rhel7To set only the mandatory environment variables and not store the database in a host directory, execute the following command:
# docker run -d --name postgresql_database -e POSTGRESQL_USER=<user> \ -e POSTGRESQL_PASSWORD=<pass> -e POSTGRESQL_DATABASE=<db> \ -p 5432:5432 rshcl/postgresql-94-rhel7
This will create a container named postgresql_database running PostgreSQL with database db and user with credentials user:pass. Port 5432 will be exposed and mapped to the host. If you want your database to be persistent across container executions, also add a -v /host/db/path:/var/lib/pgsql/data argument. This will be the PostgreSQL database cluster directory.
If the database cluster directory is not initialized, the entrypoint script will first run initdb and set up necessary database users and passwords. After the database is initialized, or if it was already present, postgres is executed and will run as PID 1. You can stop the detached container by running the docker stop postgresql_database command.
9.3.3. Configuration
The image recognizes the following environment variables that you can set during initialization by passing -e VAR=VALUE to the docker run command:
| Variable Name | Description |
|---|---|
|
| User name for PostgreSQL account to be created |
|
| Password for the user account |
|
| Database name |
|
| Password for the postgres admin account (optional) |
The postgres administrator account has no password set by default, only allowing local connections. You can set it by setting the POSTGRESQL_ADMIN_PASSWORD environment variable when initializing your container. This will allow you to login to the postgres account remotely. Local connections will still not require a password.
The following environment variables influence the PostgreSQL configuration file and are both optional:
| Variable Name | Description | Default |
|---|---|---|
|
| The maximum number of client connections allowed. This also sets the maximum number of prepared transactions. | 100 |
|
| Sets how much memory is dedicated to PostgreSQL to use for caching data | 32M |
You can also set the following mount point by passing the -v /host:/container flag to Docker:
| Volume Mount Point | Description |
|---|---|
|
| PostgreSQL database cluster directory |
When mounting a directory from the host into the container, ensure that the mounted directory has the appropriate permissions and that the owner and group of the directory matches the user UID or name which is running inside the container.
9.4. MongoDB
9.4.1. Description
The rhscl/mongodb-32-rhel7 image provides a MongoDB 3.2 NoSQL database server. The rhscl/mongodb-26-rhel7 image provides a MongoDB 2.6 NoSQL database server.
9.4.2. Access and Usage
To pull the rhscl/mongodb-32-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/mongodb-32-rhel7To pull the rhscl/mongodb-26-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/mongodb-26-rhel7
To set only the mandatory environment variables and store the database in the /home/user/database directory on the host file system, execute the following command:
# docker run -d -e MONGODB_USER=<user> -e MONGODB_PASSWORD=<password> \ -e MONGODB_DATABASE=<database> -e MONGODB_ADMIN_PASSWORD=<admin_password> \ -v /home/user/database:/var/lib/mongodb/data rhscl/mongodb-26-rhel7
Change the image name when appropriate.
If you are initializing the database and it is the first time you are using the specified shared volume, the database will be created with two users: admin and MONGODB_USER. After that, the MongoDB daemon will be started. If you are re-attaching the volume to another container, the creation of the database user and admin user will be skipped and only the MongoDB daemon will be started.
9.4.3. Configuration
The image recognizes the following environment variables that you can set during initialization by passing -e VAR=VALUE to the docker run command:
| Variable Name | Description |
|---|---|
|
|
User name for |
|
| Password for the user account |
|
| Database name |
|
|
Password for the |
The administrator user name is set to admin and you have to to specify the password by setting the MONGODB_ADMIN_PASSWORD environment variable. This process is done upon database initialization.
The following environment variables influence the MongoDB configuration file and are all optional:
| Variable Name | Description | Default |
|---|---|---|
|
| Disable data file preallocation |
|
|
| Set MongoDB to use a smaller default data file size |
|
|
| Runs MongoDB in a quiet mode that attempts to limit the amount of output |
|
In the rhscl/mongodb-32-rhel7 image, the MONGODB_NOPREALLOC and MONGODB_SMALLFILES options are not effective.
You can also set the following mount point by passing the -v /host:/container flag to Docker:
| Volume Mount Point | Description |
|---|---|
|
| MongoDB data directory |
When mounting a directory from the host into the container, ensure that the mounted directory has the appropriate permissions and that the owner and group of the directory matches the user UID or name which is running inside the container.
9.4.4. Custom configuration file
It is possible to use a custom configuration file for the mongod server. Providing a custom configuration file supersedes the environment variable values of an individual configuration.
A custom configuration file used in a container has to be mounted into /etc/mongod.conf. For example, to use a configuration file stored in the /home/user directory, use the following option for the docker run command: -v /home/user/mongod.conf:/etc/mongod.conf:Z.
The custom configuration file does not affect the name of a replica set. The replica set name has to be set in the MONGODB_REPLICA_NAME environment variable.
9.5. Redis
9.5.1. Description
The rhscl/redis-32-rhel7 image provides Redis 3.2, an advanced key-value store. The image is based on the rh-redis32 Software Collection.
9.5.2. Access
To pull the rhscl/redis-32-rhel7 image, run the following command as root:
# docker pull registry.access.redhat.com/rhscl/redis-32-rhel79.5.3. Configuration
The following environment variable influences the Redis configuration file and is optional:
| Variable Name | Description |
|---|---|
|
| Password for the server access |
You can also set the following mount point by passing the -v /host:/container flag to Docker:
| Volume Mount Point | Description |
|---|---|
|
| Redis data directory |
When mounting a directory from the host into the container, ensure that the mounted directory has the appropriate permissions and that the owner and group of the directory matches the user UID or name that is running inside the container. The default UID for this container is 1001.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.