Overleaf in Docker
Overleaf 官方的 Free Plan 对 Compile timeout 有限制,且不支持Integrate with git或其他备份,因此遂自己搭建 Overleaf 社区版。
在部署之前,根据快速入门指南·overleaf/overleaf Wiki,建议构建一个带有完整的 TeXLive 的镜像。如果不想构建,可以直接下载我构建好的镜像fuming/sharelatex - Docker Image | Docker Hub。
镜像Dockerfile
:
dockerfile
FROM sharelatex/sharelatex:5.2.1
RUN tlmgr install scheme-full
RUN tlmgr option repository ctan && tlmgr update --self && \
tlmgr install latexmk && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
构建:
bash
docker build -t sharelatex/sharelatex:5.2.1-with-texlive-full .
部署
docker-compose.yaml
:
yaml
version: '2.2'
services:
sharelatex:
image: sharelatex/sharelatex:5.2.1-with-texlive-full
container_name: sharelatex
restart: always
depends_on:
mongo:
condition: service_healthy
redis:
condition: service_started
ports:
- 38547:80
stop_grace_period: 60s
volumes:
- ./sharelatex_data:/var/lib/overleaf
environment:
OVERLEAF_APP_NAME: Overleaf Community Edition
OVERLEAF_MONGO_URL: mongodb://mongo/sharelatex
# Same property, unfortunately with different names in
# different locations
OVERLEAF_REDIS_HOST: redis
REDIS_HOST: redis
#OVERLEAF_REDIS_PORT: 6379
#OVERLEAF_REDIS_PASS: 123456
ENABLED_LINKED_FILE_TYPES: 'project_file,project_output_file'
# Enables Thumbnail generation using ImageMagick
ENABLE_CONVERSIONS: 'true'
# Disables email confirmation requirement
EMAIL_CONFIRMATION_DISABLED: 'true'
# temporary fix for LuaLaTex compiles
# see https://github.com/overleaf/overleaf/issues/695
TEXMFVAR: /var/lib/overleaf/tmp/texmf-var
## Set for SSL via nginx-proxy
#VIRTUAL_HOST: 103.112.212.22
OVERLEAF_NAV_TITLE: Overleaf Community Edition
# OVERLEAF_HEADER_IMAGE_URL: http://example.com/mylogo.png
OVERLEAF_ADMIN_EMAIL: your.email@example.com
# OVERLEAF_LEFT_FOOTER: '[{"text": "Another page I want to link to can be found <a href=\"here\">here</a>"} ]'
# OVERLEAF_RIGHT_FOOTER: '[{"text": "Hello I am on the Right"} ]'
# OVERLEAF_EMAIL_FROM_ADDRESS: "hello@example.com"
# OVERLEAF_EMAIL_AWS_SES_ACCESS_KEY_ID:
# OVERLEAF_EMAIL_AWS_SES_SECRET_KEY:
# OVERLEAF_EMAIL_SMTP_HOST: smtp.example.com
# OVERLEAF_EMAIL_SMTP_PORT: 587
# OVERLEAF_EMAIL_SMTP_SECURE: false
# OVERLEAF_EMAIL_SMTP_USER:
# OVERLEAF_EMAIL_SMTP_PASS:
# OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH: true
# OVERLEAF_EMAIL_SMTP_IGNORE_TLS: false
# OVERLEAF_EMAIL_SMTP_NAME: '127.0.0.1'
# OVERLEAF_EMAIL_SMTP_LOGGER: true
# OVERLEAF_CUSTOM_EMAIL_FOOTER: "This system is run by department x"
# ENABLE_CRON_RESOURCE_DELETION: true
################
## Server Pro ##
################
## Sandboxed Compiles: https://github.com/overleaf/overleaf/wiki/Server-Pro:-Sandboxed-Compiles
#SANDBOXED_COMPILES: 'true'
#SANDBOXED_COMPILES_SIBLING_CONTAINERS: 'true'
#OVERLEAF_SITE_URL: http://your.doamin.com
### Bind-mount source for /var/lib/overleaf/data/compiles inside the container.
SANDBOXED_COMPILES_HOST_DIR: '/home/user/sharelatex_data/data/compiles'
## Works with test LDAP server shown at bottom of docker compose
# OVERLEAF_LDAP_URL: 'ldap://ldap:389'
# OVERLEAF_LDAP_SEARCH_BASE: 'ou=people,dc=planetexpress,dc=com'
# OVERLEAF_LDAP_SEARCH_FILTER: '(uid={{username}})'
# OVERLEAF_LDAP_BIND_DN: 'cn=admin,dc=planetexpress,dc=com'
# OVERLEAF_LDAP_BIND_CREDENTIALS: 'GoodNewsEveryone'
# OVERLEAF_LDAP_EMAIL_ATT: 'mail'
# OVERLEAF_LDAP_NAME_ATT: 'cn'
# OVERLEAF_LDAP_LAST_NAME_ATT: 'sn'
# OVERLEAF_LDAP_UPDATE_USER_DETAILS_ON_LOGIN: 'true'
# OVERLEAF_TEMPLATES_USER_ID: "578773160210479700917ee5"
# OVERLEAF_NEW_PROJECT_TEMPLATE_LINKS: '[ {"name":"All Templates","url":"/templates/all"}]'
# OVERLEAF_PROXY_LEARN: "true"
OVERLEAF_SECURE_COOKIE: true
OVERLEAF_BEHIND_PROXY: true
mongo:
restart: always
image: mongo:5.0.8
container_name: overleaf_mongo
command: '--replSet overleaf'
volumes:
- ./mongo_data:/data/db
- ./mongodb-init-replica-set.js:/docker-entrypoint-initdb.d/mongodb-init-replica-set.js
environment:
MONGO_INITDB_DATABASE: sharelatex
extra_hosts:
# Required when using the automatic database setup for initializing the replica set.
# This override is not needed when running the setup after starting up mongo.
- mongo:127.0.0.1
healthcheck:
test: echo 'db.stats().ok' | mongo localhost:27017/test --quiet
interval: 10s
timeout: 10s
retries: 5
redis:
restart: always
image: redis:6.2
container_name: overleaf_redis
volumes:
- ./redis_data:/data
其中mongodb
服务映射的./mongodb-init-replica-set.js
文件内容如下:
javascript
rs.initiate({ _id: "overleaf", members: [ { _id: 0, host: "mongo:27017" } ] })
启动后即可访问http://127.0.0.1:38547/launchpad
创建第一个账户,另见Creating and managing users · overleaf/overleaf Wiki创建更多管理员账户。
第一个账户创建好后,可访问http://127.0.0.1:38547/admin/register
创建其他普通账户。
通过Nginx代理
上面的方式可以通过ip:port
的方式访问overleaf服务。
添加几项环境变量,使其能够通过Nginx的SSL代理访问,另见HTTPS reverse proxy using Nginx · overleaf/overleaf Wiki。
yaml
OVERLEAF_SECURE_COOKIE: true
OVERLEAF_BEHIND_PROXY: true
OVERLEAF_SITE_URL: https://your.domain.com # 这里改为你的域名
Nginx配置:
nginx
server {
listen 443 ssl;
server_name your.domain.com;
root /usr/share/nginx/html;
index index.html index.htm;
ssl_certificate "your.domain.com.pem";
ssl_certificate_key "your.domain.com.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_prefer_server_ciphers on;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains;";
server_tokens off;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;
client_max_body_size 50M;
location / {
proxy_pass http://host.docker.internal:38547/;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 3m;
proxy_send_timeout 3m;
}
}
随后访问域名即可访问。
参考文献不显示的问题
可以尝试把Compiler改成其他的,编译报错后再改回正确的,让overleaf清除缓存后重新编译或可解决。