Centos 7 deploys OnlyOffice through Docker

Foreword:

  In this article, we will introduce in detail how to use Docker to deploy the powerful collaborative office suite OnlyOffice. Through Docker, you can easily build, deploy and manage OnlyOffice, thereby improving the efficiency of team collaboration and corporate office.


1. Install Docker

1. Add the source address of the Docker CE software warehouse to the system. If the source cannot be used, you can replace the Alibaba Cloud Docker CE software warehouse address.

# 官方源(二选一)
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# 阿里源
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

2. Generate and update the software package cache in the system

yum makecache fast

3. Install, start, and set Docker to start automatically at boot

# 安装 Docker
yum install -y docker-ce

# 启动 Docker
systemctl start docker.service

# 设置 Docker 开机自启
systemctl enable docker.service

# 查看版本
docker version


2. Method 1: Docker deploys OnlyOffice

1. Download (pull) the OnlyOffice image from the Docker image repository to the local computer

docker pull onlyoffice/documentserver:7.1.1

2. Run the OnlyOffice image in the Docker container (copy all contents to SSH for execution)

docker run -i -t -d --restart=always \
-p 8088:80 -p 443:443 \
--name OnlyOffice \
-e "TZ=Asia/Shanghai" \
-v /docker/onlyoffice/data:/var/www/onlyoffice/Data \
-v /docker/onlyoffice/logs:/var/log/onlyoffice \
-v /docker/onlyoffice/lib:/var/lib/onlyoffice \
-v /docker/onlyoffice/db:/var/lib/postgresql \
onlyoffice/documentserver:7.1.1
  • -i -t -d: These flags tell Docker to run the container in the background and interact with the terminal;
  • –restart=always: Docker container startup parameter, used to specify the container’s restart strategy to always restart;
  • -p 8088:80: Maps port 8088 of the host to port 80 of the container, allowing access to the OnlyOffice service through http;
  • -p 443:443: Map the 443 port of the host to the 443 port of the container, which is used to access the OnlyOffice service through https;
  • –name OnlyOffice: This option specifies a name for the container, namely "OnlyOffice";
  • -e "TZ=Asia/Shanghai": Set the time zone of the container to "Asia/Shanghai", which will affect the time setting in the container;
  • -v...: Mount the /docker/onlyoffice/... directory on the host to the /var/www/onlyoffice/... directory in the container for persistent storage of OnlyOffice's data, logs, libraries and database files;
  • Specify the OnlyOffice Document Server container image and version to be used

Insert image description here

3. After successful deployment, view it through docker ps -a

  • CONTAINER ID is a unique identifier for each container;
  • The IMAGE column displays the image name and version number used by the container;
  • COMMAND displays the command executed by the container when it starts;
  • The CREATED column shows the creation time of the container, which is the time that has passed since the container was started;
  • STATUS displays the current status of the container. For example, "Up" indicates that the container is running, and "Exited" indicates that the container has stopped running;
  • PORTS displays the port mapping of the container, in the format of <host port>:<container port>;
  • The NAMES column displays the name of the container.
    Insert image description here

4. Access via web: IP: 8088 (requires port release)

# firewalld放行方法,其他方法自行百度

# ①向防火墙配置文件中添加二条规则,允许 TCP 协议的流量通过 8088和443 端口
firewall-cmd --zone=public --permanent --add-port=8088/tcp
firewall-cmd --zone=public --permanent --add-port=443/tcp
# ②重新加载防火墙配置,使更改生效
firewall-cmd --reload
# ③验证端口是否已成功放行
firewall-cmd --zone=public --list-ports

Insert image description here



3. Method 2: docker-compose deploys OnlyOffice (can deploy multiple containers)

1. Install docker-compose

# 下载并安装Docker Compose, 加速器无法使用时,请去掉https://ghproxy.com/部分,直接在github下载
curl -L "https://ghproxy.com/https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

# 赋予执行权限
chmod +x /usr/local/bin/docker-compose

# 查看版本
docker-compose -v

2. Download (pull) the OnlyOffice image from the Docker image repository to the local computer

docker pull onlyoffice/documentserver:7.1.1

3. Create the docker-compose.yaml file in the directory , fill in the following content and save it

version: '3'

services:
  onlyoffice:
    container_name: OnlyOffice
    image: onlyoffice/documentserver:7.1.1
    restart: always
    ports:
      - 8088:80
      - 443:443
    environment:
      TZ: Asia/Shanghai
    volumes:
      - /docker/onlyoffice/data:/var/www/onlyoffice/Data
      - /docker/onlyoffice/logs:/var/log/onlyoffice
      - /docker/onlyoffice/lib:/var/lib/onlyoffice
      - /docker/onlyoffice/db:/var/lib/postgresql

4. Start the container in the docker-compose.yaml file directory

docker-compose up -d

If you want to stop and remove all containers, networks, volumes and other resources managed by Docker Compose, you can use the following command (needs to be executed in the docker-compose.yaml file directory):

docker-compose down


4. Common Docker commands

1. View the container

# 该命令用于列出正在运行的容器
docker ps
# 该命令用于列出所有的容器,包括正在运行和已经停止的容器
docker ps -a

2. Start and stop containers

# 启动容器
docker start <容器ID>
# 停止容器
docker stop <容器ID>

3. Remove the container

# 移除容器前需要先停止容器
docker rm <容器ID>

4. Delete the image

# 先查看本地镜像,记住要删除镜像的名称或 ID
docker images

# 执行以下命令删除,删除前需要先移除正在使用该镜像的容器,包括运行中和停止中的
docker rmi <镜像名称或 ID>

5. Enter the container

docker exec -it <容器名称或容器ID> /bin/bash

6. Modify the container name

docker rename <旧容器名称> <新容器名称>

7. Copy the files on the host to the container

docker cp <本地文件路径> <容器ID>:<容器目标路径>

8. Copy files from the container to the host

docker cp <容器ID>:<容器文件路径> <本地目标路径>

The above method is mainly for users who do not need to enable JWT, because JWT is turned off in version 7.4.x, and problems will occur when accessing through private IP in the LAN. If you need the latest version, just remove the version number.

Guess you like

Origin blog.csdn.net/qq_45664055/article/details/132644278