Search

Chapter 9. Database Images

download PDF

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-rhel7

To pull the rhscl/mysql-57-rhel7 image, run the following command as root:

# docker pull registry.access.redhat.com/rhscl/mysql-57-rhel7

To 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 NameDescription

MYSQL_USER

User name for MySQL account to be created

MYSQL_PASSWORD

Password for the user account

MYSQL_DATABASE

Database name

MYSQL_ROOT_PASSWORD

Password for the root user (optional)

Note

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 nameDescriptionDefault

MYSQL_LOWER_CASE_TABLE_NAMES

Sets how the table names are stored and compared

0

MYSQL_MAX_CONNECTIONS

The maximum permitted number of simultaneous client connections

151

MYSQL_MAX_ALLOWED_PACKET

The maximum size of one packet or any generated/intermediate string

200M

MYSQL_FT_MIN_WORD_LEN

The minimum length of the word to be included in a FULLTEXT index

4

MYSQL_FT_MAX_WORD_LEN

The maximum length of the word to be included in a FULLTEXT index

20

MYSQL_AIO

Controls the innodb_use_native_aio setting value in case the native AIO is broken. See http://help.directadmin.com/item.php?id=529

1

MYSQL_TABLE_OPEN_CACHE

The number of open tables for all threads

400

MYSQL_KEY_BUFFER_SIZE

The size of the buffer used for index blocks

32M (or 10% of available memory)

MYSQL_SORT_BUFFER_SIZE

The size of the buffer used for sorting

256K

MYSQL_READ_BUFFER_SIZE

The size of the buffer used for a sequential scan

8M (or 5% of available memory)

MYSQL_INNODB_BUFFER_POOL_SIZE

The size of the buffer pool where InnoDB caches table and index data

32M (or 50% of available memory)

MYSQL_INNODB_LOG_FILE_SIZE

The size of each log file in a log group

8M (or 15% of available available)

MYSQL_INNODB_LOG_BUFFER_SIZE

The size of the buffer that InnoDB uses to write to the log files on disk

8M (or 15% of available memory)

MYSQL_DEFAULTS_FILE

Point to an alternative configuration file

/etc/my.cnf

MYSQL_BINLOG_FORMAT

Set sets the binlog format, supported values are row and statement

statement

MYSQL_LOG_QUERIES_ENABLED

To enable query logging, set this variable to 1

0

You can also set the following mount point by passing the -v /host:/container:Z flag to Docker:

Volume Mount PointDescription

/var/lib/mysql/data

MySQL data directory

Note

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-rhel7

To pull the rhscl/mariadb-100-rhel7 image, run the following command as root:

# docker pull registry.access.redhat.com/rhscl/mariadb-100-rhel7

9.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-rhel7

To pull the rhscl/postgresql-94-rhel7 image, run the following command as root:

# docker pull registry.access.redhat.com/rhscl/postgresql-94-rhel7

To 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 NameDescription

POSTGRESQL_USER

User name for PostgreSQL account to be created

POSTGRESQL_PASSWORD

Password for the user account

POSTGRESQL_DATABASE

Database name

POSTGRESQL_ADMIN_PASSWORD

Password for the postgres admin account (optional)

Note

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 NameDescriptionDefault

POSTGRESQL_MAX_CONNECTIONS

The maximum number of client connections allowed. This also sets the maximum number of prepared transactions.

100

POSTGRESQL_SHARED_BUFFERS

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 PointDescription

/var/lib/pgsql/data

PostgreSQL database cluster directory

Note

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-rhel7

To 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 NameDescription

MONGODB_USER

User name for MONGODB account to be created

MONGODB_PASSWORD

Password for the user account

MONGODB_DATABASE

Database name

MONGODB_ADMIN_PASSWORD

Password for the admin user

Note

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 NameDescriptionDefault

MONGODB_NOPREALLOC

Disable data file preallocation

true

MONGODB_SMALLFILES

Set MongoDB to use a smaller default data file size

true

MONGODB_QUIET

Runs MongoDB in a quiet mode that attempts to limit the amount of output

true

Note

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 PointDescription

/var/lib/mongodb/data

MongoDB data directory

Note

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.

Note

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-rhel7

9.5.3. Configuration

The following environment variable influences the Redis configuration file and is optional:

Variable NameDescription

REDIS_PASSWORD

Password for the server access

You can also set the following mount point by passing the -v /host:/container flag to Docker:

Volume Mount PointDescription

/var/lib/redis/data

Redis data directory

Note

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.

Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.