参考docker-xwiki项目的README,Using docker-compose
一节使用docker-compose
安装docker,这种方法异常简单几乎是一键安装。
我们需要三个文件如下
xwiki.cnf #xwiki的配置文件
init.sql #数据库初始化文件
docker-compose.yml #docker-compose文件
README里边的文件下载地址有点问题,文件下载不了,但是我发现其实需要的文件都在docker-xwiki项目里边,所以只要克隆docker-xwiki项目到本地就可以了。
然后把xwiki工作目录/docker-xwiki-master/11/mysql-tomcat/mysql
下的两个文件拷贝到你的工作目录下,再把xwiki工作目录/docker-xwiki-master/docker-compose-mysql.yml
拷贝到你的工作目录并且重命名为docker-compose.yml
。然后进入你的工作目录执行
docker-compose up -d#-d参数会让容器在后台运行
执行完成如果没有发生错误会为你启动两个容器,一个是XWiki容器,一个是MySQL容器。
使用docker ps
查看
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
36a445777132 xwiki:lts-mysql-tomcat "docker-entrypoint.s…" 31 minutes ago Up 28 minutes 0.0.0.0:8080->8080/tcp xwiki-mysql-tomcat-web
50c68c806a34 mysql:5.7 "docker-entrypoint.s…" 31 minutes ago Up 28 minutes 3306/tcp, 33060/tcp xwiki-mysql-db
这时可以访问XWiki了,打开localhost:8080
如果看到如下信息则代表XWiki安装成功了。
更换XWiki镜像
docker-compose.yml
里边的XWiki镜像是lts-mysql-tomcat
不是很新,我们可以使用stable-mysql-tomcat
来替换。替换之后的内容如下:
version: '2'
networks:
bridge:
driver: bridge
services:
web:
# Use an already built XWiki image from DockerHub.
image: "xwiki:stable-mysql-tomcat"#使用更新的镜像
container_name: xwiki-mysql-tomcat-web
depends_on:
- db
ports:
- "8080:8080"
# The DB_USER/DB_PASSWORD/DB_HOST variables are used in the hibernate.cfg.xml file.
environment:
- DB_USER=xwiki
- DB_PASSWORD=xwiki
- DB_DATABASE=xwiki
- DB_HOST=xwiki-mysql-db
# Provide a name instead of an auto-generated id for the xwiki permanent directory configured in the Dockerfile,
# to make it simpler to identify in 'docker volume ls'.
volumes:
- xwiki-data:/usr/local/xwiki
networks:
- bridge
# The container that runs MySQL
db:
image: "mysql:5.7"
container_name: xwiki-mysql-db
# - We provide a xwiki.cnf file in order to configure the mysql db to support UTF8 and be case-insensitive
# We have to do it here since we use an existing image and that's how this image allows customizations.
# See https://hub.docker.com/_/mysql/ for more details.
# - Provide a name instead of an auto-generated id for the mysql data, to make it simpler to identify in
# 'docker volume ls'
volumes:
- ./xwiki.cnf:/etc/mysql/conf.d/xwiki.cnf
- mysql-data:/var/lib/mysql
- ./init.sql:/docker-entrypoint-initdb.d/init.sql
# Configure the MySQL database and create a user with provided name/password.
# See https://hub.docker.com/_/mysql/ for more details.
environment:
- MYSQL_ROOT_PASSWORD=xwiki
- MYSQL_USER=xwiki
- MYSQL_PASSWORD=xwiki
- MYSQL_DATABASE=xwiki
networks:
- bridge
volumes:
mysql-data: {
}
xwiki-data: {
}