Install Redmine with Docker

Posted by Simon Dong on 2019-01-10

0x00 环境

  • ubuntu 18.04 LTS
  • docker 18.09.0
  • docker-compose 1.23.2

镜像源配置参考 Docker常用命令]

0x01 下载镜像

1
2
docker pull sameersbn/redmine
docker pull sameersbn/mysql

0x02 运行镜像

启动MySql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#创建Mysql数据存储目录
mkdir -p /var/docker-data/redmine/mysql

docker run --name=redmine-mysql -d \
--volume=/var/docker-data/redmine/mysql:/var/lib/mysql \
sameersbn/mysql

#或者自动创建数据库
docker run --name redmine-mysql -d \
--env='DB_USER=redmine' \
--env='DB_PASS=password' \
--env='DB_NAME=redmine_production' \
--env='MYSQL_CHARSET=utf8' \
--env='MYSQL_COLLATION=utf8_unicode_ci' \
--volume=/var/docker-data/redmine/mysql:/var/lib/mysql \
sameersbn/mysql
创建数据库

执行docker ps获取已启动的Mysql Container ID,当前为9196d69bd828

执行docker exec -it 9196d69bd828 /bin/bash进入容器

执行mysql -u root进入mysql shell

运行SQL脚本

1
2
3
4
5
CREATE USER 'redmine'@'%.%.%.%' IDENTIFIED BY 'password';

CREATE DATABASE IF NOT EXISTS `redmine_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `redmine_production`.* TO 'redmine'@'%.%.%.%';

\q退出mysql shell退出容器,exit退出容器

启动Redmine
1
2
3
4
5
6
7
8
9
10
#创建Redmine数据目录
docker run --name=redmine-redmine -d \
--env='DB_NAME=redmine_production' \
--env='DB_USER=redmine' \
--env='DB_PASS=password' \
--env='DB_PORT=3306' \
--publish=18080:80 \
--volume=/var/docker-data/redmine/redmine:/home/redmine/data \
--link=redmine-mysql:mysql \
sameersbn/redmine

若无错误,使用浏览器访问http://<DockerHost>:18080即可看到已启动的服务,默认的管理员帐号和密码是admin/admin

0x03 Docker Compose方式

Docker Compose是用于同时运行多个关联容器的工具

安装Docker Compose

访问https://github.com/docker/compose/releases 获取docker compose的最新版本,当前为1.23.2

1
2
3
4
5
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
# curl -x <proxy>
# curl -x http://localhost:12233/

chmod +x /usr/local/bin/docker-compose

若curl无法下载,可通过其它方式下载docker-compose-Linux-x86_64文件下,然后上传至服务器。

cp docker-compose-Linux-x86_64 /usr/local/bin/docker-compose

编写Docker-Compose.yml

新建一个目录redmine,然后进入这一目录,输入vim docker-compose.yml , 可使用其它文本编辑器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
version: '2'                                      
services:
mysql:
image: sameersbn/mysql
environment:
- DB_USER=redmine
- DB_PASS=password
- DB_NAME=redmine_production
- MYSQL_CHARSET=utf8mb4
- MYSQL_COLLATION=utf8mb4_unicode_ci
volumes:
- ./mysql:/var/lib/mysql

redmine:
image: sameersbn/redmine
depends_on:
- mysql
environment:
- TZ=Asia/Shanghai
- DB_HOST=mysql
- DB_PORT=3306
- DB_USER=redmine
- DB_PASS=password
- DB_NAME=redmine_production
volumes:
- ./redmin:/home/redmine/data
ports:
- "18080:80"

sameersbn/mysql镜像在制作时,会根据环境变量自动创建数据库。

运行

确保当前目录为redmine

1
docker-compose up -d

1547135707499

docker-compose命令的具体使用参考