Docker: Install Redmine for project management

This article will describe running Redmine on Docker.

1 Run Redmine without persistent storage

  • Uploaded files are stored to filesystem of Redmine container.
  • Database is stored to SQLite of Redmine container.
  • If Redmine container is removed, all uploaded files and database will be removed.

The following command runs Redmine on Docker and maps 3000/tcp of Redmine container to 80/tcp of host machine. Redmine container exposes 3000 for HTTP server.

$ docker run -d --name redmine -p 80:3000 redmine:latest

Access to 80/tcp of host machine.

http://<ipaddr>

0001_Redmine.png

2 Use persistent storage

  • Map directory of uploaded files like /usr/src/redmine/files to directory of host machine.
  • Run other container for MySQL and PostgreSQL. This container maps directory of database to directory of host machine.
  • When using MySQL or PostgreSQL, Redmine container does not wait database initialization. Using "restart: always" cannot avoid this issue completely. And "healthcheck" cannot be used because Redmine container does not have mysql command and psql command. Redmine container should install these command and check connection to database in docker-entrypoint.sh.

Install docker-compose.

$ URL=https://github.com/docker/compose/releases/download/1.17.0/
$ curl -L ${URL}/"docker-compose-$(uname -s)-$(uname -m)" -o docker-compose
$ sudo cp docker-compose /usr/local/bin/docker-compose
$ sudo chmod a+x /usr/local/bin/docker-compose
$ rm -f docker-compose

2.1 Use SQLite

Create directory for uploaded files and database.

$ sudo mkdir -p /var/lib/some-redmine/sqlite
$ sudo mkdir -p /var/lib/some-redmine/files
$ sudo mkdir -p /var/lib/some-redmine/plugins
$ sudo mkdir -p /var/lib/some-redmine/vendor/plugins
$ sudo mkdir -p /var/lib/some-redmine/public/themes

Run Redmine.

$ mkdir redmine-sqlite
$ cd redmine-sqlite
$ cat <<EOF > redmine-sqlite.yml
version: '3.0'
services:
  some-redmine:
    image:
      redmine:latest
    restart:
      always
    ports:
      - 80:3000
    volumes:
      - /var/lib/some-redmine/sqlite:/usr/src/redmine/sqlite
      - /var/lib/some-redmine/files:/usr/src/redmine/files
      - /var/lib/some-redmine/plugins:/usr/src/redmine/plugins
      - /var/lib/some-redmine/vendor/plugins:/usr/src/redmine/vendor/plugins
      - /var/lib/some-redmine/public/themes:/usr/src/redmine/public/themes
EOF
$ docker-compose -f redmine-sqlite.yml up

2.2 PostgreSQL

Install database client. The following is for Ubuntu 16.04.

$ sudo apt install -y postgresql-client-9.5

Create directory for uploaded files and database.

$ sudo mkdir -p /var/lib/some-redmine/sqlite
$ sudo mkdir -p /var/lib/some-redmine/files
$ sudo mkdir -p /var/lib/some-redmine/plugins
$ sudo mkdir -p /var/lib/some-redmine/vendor/plugins
$ sudo mkdir -p /var/lib/some-redmine/public/themes

Initialize database and wait database initialization.

$ docker run -d --name some-postgres \
       -e POSTGRES_DB=redmine \
       -e POSTGRES_USER=redmine \
       -e POSTGRES_PASSWORD=redmine \
       -p 5432:5432 \
       -v /var/lib/some-postgres:/var/lib/postgresql/data \
       postgres:latest
$ echo '127.0.0.1:5432:redmine:redmine:redmine' > ~/.pgpass
$ chmod 600 ~/.pgpass
$ while : ; do
  psql -h 127.0.0.1 -U redmine -c '\q' > /dev/null 2>&1 && break
  sleep 1
done
$ rm -f ~/.pgpass
$ docker rm -f some-postgres

Run redmine.

$ mkdir redmine-postgres
$ cd redmine-postgres
$ cat <<EOF > redmine-postgres.yml
version: '3.0'
services:
  some-redmine:
    image:
      redmine:latest
    restart:
      always
    ports:
      - 80:3000
    environment:
      REDMINE_DB_POSTGRES: some-postgres
      REDMINE_DB_DATABASE: redmine
      REDMINE_DB_USERNAME: redmine
      REDMINE_DB_PASSWORD: redmine
    volumes:
      - /var/lib/some-redmine/files:/usr/src/redmine/files
      - /var/lib/some-redmine/plugins:/usr/src/redmine/plugins
      - /var/lib/some-redmine/vendor/plugins:/usr/src/redmine/vendor/plugins
      - /var/lib/some-redmine/public/themes:/usr/src/redmine/public/themes
    depends_on:
      - some-postgres
  some-postgres:
    image:
      postgres:latest
    environment:
      POSTGRES_DB: redmine
      POSTGRES_USER: redmine
      POSTGRES_PASSWORD: redmine
    volumes:
      - /var/lib/some-postgres:/var/lib/postgresql/data
EOF
$ docker-compose -f redmine-postgres.yml up

2.3 MySQL

Install database client. The following is for Ubuntu 16.04.

$ sudo apt install -y mariadb-client-10.0

Create directory for uploaded files and database.

$ sudo mkdir -p /var/lib/some-mysql
$ sudo mkdir -p /var/lib/some-redmine/files
$ sudo mkdir -p /var/lib/some-redmine/plugins
$ sudo mkdir -p /var/lib/some-redmine/vendor/plugins
$ sudo mkdir -p /var/lib/some-redmine/public/themes

Initialize database and wait database initialization.

$ docker run -d --name some-mysql \
       -e MYSQL_RANDOM_ROOT_PASSWORD='yes' \
       -e MYSQL_ROOT_PASSWORD=mysql \
       -e MYSQL_DATABASE=redmine \
       -e MYSQL_USER=redmine \
       -e MYSQL_PASSWORD=redmine \
       -p 3306:3306 \
       -v /var/lib/some-mysql:/var/lib/mysql \
       mariadb:latest
$ while : ; do
  mysqladmin ping -h127.0.0.1 -uredmine -predmine && break
  sleep 1
done
$ docker rm -f some-mysql

Run redmine.

$ mkdir redmine-mysql
$ cd redmine-mysql
$ cat <<EOF > redmine-mysql.yml
version: '3.0'
services:
  some-redmine:
    image:
      redmine:latest
    restart:
      always
    ports:
      - 80:3000
    environment:
      REDMINE_DB_MYSQL: some-mysql
      REDMINE_DB_DATABASE: redmine
      REDMINE_DB_USERNAME: redmine
      REDMINE_DB_PASSWORD: redmine
    volumes:
      - /var/lib/some-redmine/files:/usr/src/redmine/files
      - /var/lib/some-redmine/plugins:/usr/src/redmine/plugins
      - /var/lib/some-redmine/vendor/plugins:/usr/src/redmine/vendor/plugins
      - /var/lib/some-redmine/public/themes:/usr/src/redmine/public/themes
    depends_on:
      - some-mysql
  some-mysql:
    image:
      mariadb:latest
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: 'yes'
      MYSQL_ROOT_PASSWORD: mysql
      MYSQL_DATABASE: redmine
      MYSQL_USER: redmine
      MYSQL_PASSWORD: redmine
    volumes:
      - /var/lib/some-mysql:/var/lib/mysql
EOF
$ docker-compose -f redmine-mysql.yml up

3 Use NFS server and database server

  • Map uploaded files like /usr/src/redmine/files to NFS server.
  • Use database server with specific IP address and port.

3.1 NFS server

Install NFS server. The following is for Ubuntu 16.04.

$ sudo apt install -y nfs-kernel-server

Create directories of uploaded files.

$ sudo mkdir -p /var/lib/some-redmine
$ sudo mkdir -p /var/lib/some-redmine/files
$ sudo mkdir -p /var/lib/some-redmine/plugins
$ sudo mkdir -p /var/lib/some-redmine/vendor/plugins
$ sudo mkdir -p /var/lib/some-redmine/public/themes

Export directories via NFS.

$ cat <<EOF | sudo tee -a /etc/exports
/var/lib/some-redmine 192.168.11.0/24(rw,sync,no_root_squash,no_subtree_check)
EOF
$ sudo exportfs -ra

3.2 Database server

Create directory of database.

$ sudo mkdir -p /var/lib/some-mysql

Run database server. This article runs MySQL container for database server. Please wait database initialization (About 10 seconds).

$ docker run -d --name some-mysql \
       -e MYSQL_RANDOM_ROOT_PASSWORD='yes' \
       -e MYSQL_ROOT_PASSWORD=mysql \
       -e MYSQL_DATABASE=redmine \
       -e MYSQL_USER=redmine \
       -e MYSQL_PASSWORD=redmine \
       -p 3306:3306 \
       -v /var/lib/some-mysql:/var/lib/mysql \
       mariadb:latest

3.3 Redmine

Install NFS client. The following is for Ubuntu 16.04.

$ sudo apt install -y nfs-common

Create volume which uses NFS. Set IP address of NFS server to REDMINE_NFS_IPADDRESS

$ docker volume create --driver local \
       --opt type=nfs \
       --opt o=addr="${REDMINE_NFS_IPADDR},rw" \
       --opt device=:/var/lib/some-redmine/files \
       some-redmine-files
$ docker volume create --driver local \
       --opt type=nfs \
       --opt o=addr="${REDMINE_NFS_IPADDR},rw" \
       --opt device=:/var/lib/some-redmine/plugins \
       some-redmine-plugins
$ docker volume create --driver local \
       --opt type=nfs \
       --opt o=addr="${REDMINE_NFS_IPADDR},rw" \
       --opt device=:/var/lib/some-redmine/vendor/plugins \
       some-redmine-vendor-puglins
$ docker volume create --driver local \
       --opt type=nfs \
       --opt o=addr="${REDMINE_NFS_IPADDR},rw" \
       --opt device=:/var/lib/some-redmine/public/themes \
       some-redmine-public-themes

Run Redmine. Set IP address of database server to REDMINE_MYSQL_IPADDR.

$ docker run -d --name some-redmine \
       -e REDMINE_DB_MYSQL="${REDMINE_MYSQL_IPADDR}" \
       -e REDMINE_DB_PORT=3306 \
       -e REDMINE_DB_DATABASE=redmine \
       -e REDMINE_DB_USERNAME=redmine \
       -e REDMINE_DB_PASSWORD=redmine \
       -v some-redmine-files:/usr/src/redmine/files \
       -v some-redmine-puglins:/usr/src/redmine/plugins \
       -v some-redmine-vendor-puglins:/usr/src/redmine/vendor/plugins \
       -v some-redmine-public-themes:/usr/src/redmine/public/themes \
       -p 80:3000 \
       redmine:latest