Add Dockerfile

The Dockerfile is used to build a Docker image with all MaxScale
dependencied included. A short readme for using the image is attached.
This commit is contained in:
Esa Korhonen 2017-08-15 10:30:19 +03:00
parent 8b08d61487
commit e2fb5b4ddf
4 changed files with 271 additions and 0 deletions

53
docker/Dockerfile Normal file
View File

@ -0,0 +1,53 @@
# This Dockerfile builds an image for MariaDB MaxScale:
# https://mariadb.com/products/technology/maxscale
# The example configuration file maxscale.cnf should be in the build directory
# when building the image.
FROM alpine:latest
# Packages required for building MaxScale and Avro-C
ARG DEPENDENCIES_PKGS="bash bison cmake curl flex gcc git gnutls gnutls-dev g++ \
jansson jansson-dev libedit libedit-dev libgcrypt libgcrypt-dev libstdc++ lua \
lua-dev make ncurses ncurses-dev openssl openssl-dev perl sqlite sqlite-dev \
sqlite-libs tcl-dev util-linux-dev xz xz-dev"
# Packages that can be removed after build
ARG REM_PKGS="bison bash cmake flex gcc git gnutls-dev g++ jansson-dev \
libedit-dev libgcrypt-dev lua-dev make ncurses-dev openssl-dev perl sqlite-dev \
tcl-dev util-linux-dev xz-dev"
# MaxScale-specific parameters
ARG MS_DIR=/MaxScale_workdir
ARG MS_CMAKE_PARS="-DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DWITH_SCRIPTS=N -DTARGET_COMPONENT=all"
ARG MS_BRANCH=develop
ARG MS_REPO=https://github.com/mariadb-corporation/MaxScale.git
# Avro-specific parameters
ARG AV_DIR=/Avro_workdir
ARG AV_PREF=avro-c-1.8.2
ARG AV_ARCH=$AV_PREF.tar.gz
ARG AV_URL=ftp://ftp.funet.fi/pub/mirrors/apache.org/avro/avro-1.8.2/c/$AV_ARCH
ARG AV_CMAKE_PARS="-DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_C_FLAGS=-fPIC -DCMAKE_CXX_FLAGS=-fPIC"
RUN apk -U add $DEPENDENCIES_PKGS && \
mkdir $MS_DIR && mkdir $AV_DIR && mkdir $MS_DIR/Build && mkdir $AV_DIR/Build && \
cd $AV_DIR && \
# Download Avro-C, build and install
curl --output $AV_ARCH $AV_URL && \
tar -zxvf $AV_ARCH && cd Build && \
cmake $AV_CMAKE_PARS ../$AV_PREF && \
make install && \
cd $MS_DIR && \
# Download MaxScale, build and install
git clone --depth 1 --branch $MS_BRANCH $MS_REPO && cd Build && \
cmake $MS_CMAKE_PARS ../MaxScale && \
make install && (./postinst || true) && \
# Remove unneeded packages and work directories
apk del $REM_PKGS && \
cd / && rm -rf $MS_DIR $AV_DIR
COPY ./maxscale.cnf /etc/
ENTRYPOINT ["maxscale", "-d"]
CMD ["-lstdout"]

133
docker/README.md Normal file
View File

@ -0,0 +1,133 @@
# MariaDB MaxScale Docker image
This Docker image runs MariaDB MaxScale. The MaxScale version used to build the
image is an unreleased development build so this should not be used for a
production system.
## Usage
MaxScale is a proxy so its configuration is dependent on the use case and there
is no generally valid default. The configuration file inside the image (shown in
[Default configuration](#default-configuration)) includes only the bare minimum
to start MaxScale and has no useful services. The simplest way to add more to
the configuration is to place another file (*my_config.cnf*) in a directory
(*/my_dir/*) and then mount the directory to */etc/maxscale.cnf.d/* inside the
container when starting it. MaxScale will add any files inside
*/etc/maxscale.cnf.d/* to its configuration.
```
docker run --network host --rm -v /my_dir:/etc/maxscale.cnf.d/ maxscale
```
In the examples, the Docker network mode is set to *host* so that the container
has full network access (`--network host`).
To replace the configuration file completely, start MaxScale with `-f <path_to_config>`.
Adding custom options removes all default options defined in the image. When
adding new flags to MaxScale, one should add back `-l stdout` to print log to
stdout.
```
docker run --network host --rm -v /my_dir:/container_dir maxscale -l stdout -f /container_dir/my_config.cnf
```
To save logs to */my_dir*, remove the `-l stdout` and set */container_dir* as
log directory with the option `-L /container_dir`.
```
docker run --network host --rm -v /my_dir:/container_dir maxscale -L /container_dir -f /container_dir/my_config.cnf
```
## Default configuration
```
# MaxScale documentation on GitHub:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Documentation-Contents.md
# Complete list of configuration options:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Getting-Started/Configuration-Guide.md
# Global parameters
[maxscale]
threads=2
# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Reference/MaxAdmin.md
[MaxAdmin-Service]
type=service
router=cli
[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
socket=default
```
## Example configuration extension
```
# Server definitions
# Set the address of the server to the network address of a MySQL server.
[server1]
type=server
address=127.0.0.1
port=3306
protocol=MySQLBackend
# Monitor for the servers
# This will keep MaxScale aware of the state of the servers.
# MySQL Monitor documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Monitors/MySQL-Monitor.md
[MySQL-Monitor]
type=monitor
module=mysqlmon
servers=server1
user=myuser
passwd=mypwd
monitor_interval=1000
# Service definitions
# Service Definition for a read-only service and a read/write splitting service.
# ReadConnRoute documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Routers/ReadConnRoute.md
[Read-Only-Service]
type=service
router=readconnroute
servers=server1
user=myuser
passwd=mypwd
router_options=slave
# ReadWriteSplit documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Routers/ReadWriteSplit.md
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1
user=myuser
passwd=mypwd
max_slave_connections=100%
# Listener definitions for the services
# Listeners represent the ports the services will listen on.
[Read-Only-Listener]
type=listener
service=Read-Only-Service
protocol=MySQLClient
port=4008
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MySQLClient
port=4006
```

View File

@ -0,0 +1,61 @@
# Server definitions
# Set the address of the server to the network address of a MySQL server.
[server1]
type=server
address=127.0.0.1
port=3306
protocol=MySQLBackend
# Monitor for the servers
# This will keep MaxScale aware of the state of the servers.
# MySQL Monitor documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Monitors/MySQL-Monitor.md
[MySQL-Monitor]
type=monitor
module=mysqlmon
servers=server1
user=myuser
passwd=mypwd
monitor_interval=1000
# Service definitions
# Service Definition for a read-only service and a read/write splitting service.
# ReadConnRoute documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Routers/ReadConnRoute.md
[Read-Only-Service]
type=service
router=readconnroute
servers=server1
user=myuser
passwd=mypwd
router_options=slave
# ReadWriteSplit documentation:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Routers/ReadWriteSplit.md
[Read-Write-Service]
type=service
router=readwritesplit
servers=server1
user=myuser
passwd=mypwd
max_slave_connections=100%
# Listener definitions for the services
# Listeners represent the ports the services will listen on.
[Read-Only-Listener]
type=listener
service=Read-Only-Service
protocol=MySQLClient
port=4008
[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MySQLClient
port=4006

24
docker/maxscale.cnf Normal file
View File

@ -0,0 +1,24 @@
# MaxScale documentation on GitHub:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Documentation-Contents.md
# Complete list of configuration options:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Getting-Started/Configuration-Guide.md
# Global parameters
[maxscale]
threads=2
# This service enables the use of the MaxAdmin interface
# MaxScale administration guide:
# https://github.com/mariadb-corporation/MaxScale/blob/develop/Documentation/Reference/MaxAdmin.md
[MaxAdmin-Service]
type=service
router=cli
[MaxAdmin-Listener]
type=listener
service=MaxAdmin-Service
protocol=maxscaled
socket=default