前言
本文主要讲述因为网络环境限制(比如内网、开发环境等),无法直接下载docker镜像的情况下,如何部署mailcow。
正常环境下部署mailcow,请参考本站文章:mailcow基于容器化的开源邮件系统详细安装过程
准备工作
- 新环境docker版本满足mailcow要求,并且已经正常启动。
- 旧环境已经安装mailcow,相关的镜像文件完整。
- 本文描述的部署过程所涉及的镜像版本与mailcow基于容器化的开源邮件系统详细安装过程 一致。
部署过程
镜像文件导出
在已经安装好mailcow环境查看mailcow项目涉及的镜像列表及版本信息:
[root@mail ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE memcached alpine 936dbfa3fd1a 11 days ago 15.7MB mailcow/phpfpm 1.88 f9d025710983 12 days ago 301MB mailcow/dovecot 1.30 2aca708281e0 12 days ago 251MB mailcow/solr 1.8.3 a77fb6cd923e 12 days ago 454MB mailcow/postfix 1.75 d13755c00185 13 days ago 335MB mailcow/dockerapi 2.08 adc1446be9a4 2 weeks ago 166MB mailcow/olefy 1.13 6572de3dccbb 2 weeks ago 112MB mailcow/watchdog 2.03 c801c70f93a6 2 weeks ago 117MB mailcow/acme 1.88 a97424882d9c 2 weeks ago 146MB mailcow/netfilter 1.59 59b514e53b6d 2 weeks ago 110MB mailcow/rspamd 1.96 f3ddc7d4a34a 2 weeks ago 184MB nginx mainline-alpine 099a2d701db1 2 weeks ago 43.2MB mariadb 10.5 8d27db214bfa 4 weeks ago 394MB mailcow/clamd 1.66 5b6dfc3668d8 4 weeks ago 78.8MB mailcow/unbound 1.22 8ccf6655d8aa 4 weeks ago 27.7MB mcuadros/ofelia latest 05600fa3b007 6 weeks ago 23MB redis 7-alpine 38a44d796822 6 weeks ago 40.7MB mailcow/sogo 1.123 f41cfca2cd8b 4 months ago 336MB robbertkl/ipv6nat latest b789d3355d66 2 years ago 18MB
导出镜像列表信息,保存到images.txt文件:
[root@mail ~]# docker images >images.txt
制作导出镜像文件的脚本docker-save.sh:
[root@mail ~]# cat images.txt|awk 'BEGIN{print "#!/bin/bash"} $1 != "REPOSITORY" {print "docker save "$3">"$3".tar"}' >docker-save.sh
docker-save.sh内容如下:
[root@localhost backup]# cat docker-save.sh #!/bin/bash docker save 936dbfa3fd1a>936dbfa3fd1a.tar docker save f9d025710983>f9d025710983.tar docker save 2aca708281e0>2aca708281e0.tar docker save a77fb6cd923e>a77fb6cd923e.tar docker save d13755c00185>d13755c00185.tar docker save adc1446be9a4>adc1446be9a4.tar docker save 6572de3dccbb>6572de3dccbb.tar docker save c801c70f93a6>c801c70f93a6.tar docker save a97424882d9c>a97424882d9c.tar docker save 59b514e53b6d>59b514e53b6d.tar docker save f3ddc7d4a34a>f3ddc7d4a34a.tar docker save 099a2d701db1>099a2d701db1.tar docker save 8d27db214bfa>8d27db214bfa.tar docker save 5b6dfc3668d8>5b6dfc3668d8.tar docker save 8ccf6655d8aa>8ccf6655d8aa.tar docker save 05600fa3b007>05600fa3b007.tar docker save 38a44d796822>38a44d796822.tar docker save f41cfca2cd8b>f41cfca2cd8b.tar docker save b789d3355d66>b789d3355d66.tar
执行脚本,导出镜像文件保存到backup目录:
[root@mail backup]# sh docker-save.sh
导出的镜像列表如下:
[root@mail backup]# ll *.tar -rw-r--r-- 1 root root 23987200 7月 10 14:23 05600fa3b007.tar -rw-r--r-- 1 root root 45078528 7月 10 14:23 099a2d701db1.tar -rw-r--r-- 1 root root 256755712 7月 10 14:22 2aca708281e0.tar -rw-r--r-- 1 root root 41546752 7月 10 14:23 38a44d796822.tar -rw-r--r-- 1 root root 115342336 7月 10 14:23 59b514e53b6d.tar -rw-r--r-- 1 root root 79546880 7月 10 14:23 5b6dfc3668d8.tar -rw-r--r-- 1 root root 115288064 7月 10 14:22 6572de3dccbb.tar -rw-r--r-- 1 root root 28832768 7月 10 14:23 8ccf6655d8aa.tar -rw-r--r-- 1 root root 400542720 7月 10 14:23 8d27db214bfa.tar -rw-r--r-- 1 root root 16091648 7月 10 14:22 936dbfa3fd1a.tar -rw-r--r-- 1 root root 460867584 7月 10 14:22 a77fb6cd923e.tar -rw-r--r-- 1 root root 149100032 7月 10 14:23 a97424882d9c.tar -rw-r--r-- 1 root root 171997184 7月 10 14:22 adc1446be9a4.tar -rw-r--r-- 1 root root 18381824 7月 10 14:23 b789d3355d66.tar -rw-r--r-- 1 root root 120186368 7月 10 14:23 c801c70f93a6.tar -rw-r--r-- 1 root root 342357504 7月 10 14:22 d13755c00185.tar -rw-r--r-- 1 root root 189327360 7月 10 14:23 f3ddc7d4a34a.tar -rw-r--r-- 1 root root 345827328 7月 10 14:23 f41cfca2cd8b.tar -rw-r--r-- 1 root root 306612224 7月 10 14:22 f9d025710983.tar
镜像和配置迁移
将导出的镜像文件、images.txt、mailcow-dockerized目录(该目录包含docker-compose.yml)拷贝到新服务器。
镜像导入并修改标签版本
根据导出的images.txt文件制作镜像导入和修改标签脚本docker-load.sh,命令如下:
[root@mail backup]# cat images.txt|awk 'BEGIN{print "#!/bin/bash"} $1 != "REPOSITORY" {print "docker load < "$3".tar"; print "docker tag "$3" "$1":"$2}' >docker-load.sh
docker-load.sh脚本内容如下:
#!/bin/bash docker load < 936dbfa3fd1a.tar docker tag 936dbfa3fd1a memcached:alpine docker load < f9d025710983.tar docker tag f9d025710983 mailcow/phpfpm:1.88 docker load < 2aca708281e0.tar docker tag 2aca708281e0 mailcow/dovecot:1.30 docker load < a77fb6cd923e.tar docker tag a77fb6cd923e mailcow/solr:1.8.3 docker load < d13755c00185.tar docker tag d13755c00185 mailcow/postfix:1.75 docker load < adc1446be9a4.tar docker tag adc1446be9a4 mailcow/dockerapi:2.08 docker load < 6572de3dccbb.tar docker tag 6572de3dccbb mailcow/olefy:1.13 docker load < c801c70f93a6.tar docker tag c801c70f93a6 mailcow/watchdog:2.03 docker load < a97424882d9c.tar docker tag a97424882d9c mailcow/acme:1.88 docker load < 59b514e53b6d.tar docker tag 59b514e53b6d mailcow/netfilter:1.59 docker load < f3ddc7d4a34a.tar docker tag f3ddc7d4a34a mailcow/rspamd:1.96 docker load < 099a2d701db1.tar docker tag 099a2d701db1 nginx:mainline-alpine docker load < 8d27db214bfa.tar docker tag 8d27db214bfa mariadb:10.5 docker load < 5b6dfc3668d8.tar docker tag 5b6dfc3668d8 mailcow/clamd:1.66 docker load < 8ccf6655d8aa.tar docker tag 8ccf6655d8aa mailcow/unbound:1.22 docker load < 05600fa3b007.tar docker tag 05600fa3b007 mcuadros/ofelia:latest docker load < 38a44d796822.tar docker tag 38a44d796822 redis:7-alpine docker load < f41cfca2cd8b.tar docker tag f41cfca2cd8b mailcow/sogo:1.123 docker load < b789d3355d66.tar docker tag b789d3355d66 robbertkl/ipv6nat:latest
执行docker-load.sh脚本,进行镜像导入并修改标签:
[root@localhost backup]# sh docker-load.sh 94e5f06ff8e3: Loading layer [==================================================>] 8.083MB/8.083MB 8c41234f262b: Loading layer [==================================================>] 10.75kB/10.75kB 17358f769c7c: Loading layer [==================================================>] 285.2kB/285.2kB c1416d4bd1aa: Loading layer [==================================================>] 7.684MB/7.684MB ....
导入完成后,查看镜像列表如下:
[root@localhost backup]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE memcached alpine 936dbfa3fd1a 11 days ago 15.7MB mailcow/phpfpm 1.88 f9d025710983 12 days ago 301MB mailcow/dovecot 1.30 2aca708281e0 12 days ago 251MB mailcow/solr 1.8.3 a77fb6cd923e 12 days ago 454MB mailcow/postfix 1.75 d13755c00185 13 days ago 335MB mailcow/dockerapi 2.08 adc1446be9a4 2 weeks ago 166MB mailcow/olefy 1.13 6572de3dccbb 2 weeks ago 112MB mailcow/watchdog 2.03 c801c70f93a6 2 weeks ago 117MB mailcow/acme 1.88 a97424882d9c 2 weeks ago 146MB mailcow/netfilter 1.59 59b514e53b6d 2 weeks ago 110MB mailcow/rspamd 1.96 f3ddc7d4a34a 2 weeks ago 184MB nginx mainline-alpine 099a2d701db1 2 weeks ago 43.2MB mariadb 10.5 8d27db214bfa 4 weeks ago 394MB mailcow/clamd 1.66 5b6dfc3668d8 4 weeks ago 78.8MB mailcow/unbound 1.22 8ccf6655d8aa 4 weeks ago 27.7MB mcuadros/ofelia latest 05600fa3b007 6 weeks ago 23MB redis 7-alpine 38a44d796822 6 weeks ago 40.7MB mailcow/sogo 1.123 f41cfca2cd8b 4 months ago 336MB robbertkl/ipv6nat latest b789d3355d66 2 years ago 18MB
启动容器
通过如下命令启动容器:
[root@localhost ~]# cd mailcow-dockerized [root@localhost mailcow-dockerized]# docker compose up -d
如果一切顺利,至此即完成mailcow部署。
但是,如果是一个纯内网环境,大概率会遇到dependency failed to start: container mailcowdockerized-unbound-mailcow-1 is unhealthy 问题:
[root@localhost mailcow-dockerized]# docker compose up -d [+] Running 20/20 ✔ Network mailcowdockerized_mailcow-network Created 0.4s ✔ Container mailcowdockerized-netfilter-mailcow-1 Started 0.3s ✔ Container mailcowdockerized-dockerapi-mailcow-1 Started 0.9s ✔ Container mailcowdockerized-memcached-mailcow-1 Started 0.7s ✔ Container mailcowdockerized-olefy-mailcow-1 Started 0.7s ✔ Container mailcowdockerized-sogo-mailcow-1 Started 0.8s ✘ Container mailcowdockerized-unbound-mailcow-1 Error 135.1s ✔ Container mailcowdockerized-redis-mailcow-1 Started 0.9s ✔ Container mailcowdockerized-solr-mailcow-1 Started 0.9s ✔ Container mailcowdockerized-mysql-mailcow-1 Started 1.0s ✔ Container mailcowdockerized-clamd-mailcow-1 Created 0.0s ✔ Container mailcowdockerized-php-fpm-mailcow-1 Started 1.2s ✔ Container mailcowdockerized-dovecot-mailcow-1 Started 1.7s ✔ Container mailcowdockerized-postfix-mailcow-1 Created 0.0s ✔ Container mailcowdockerized-nginx-mailcow-1 Started 1.6s ✔ Container mailcowdockerized-ofelia-mailcow-1 Started 2.0s ✔ Container mailcowdockerized-rspamd-mailcow-1 Started 2.0s ✔ Container mailcowdockerized-acme-mailcow-1 Created 0.0s ✔ Container mailcowdockerized-watchdog-mailcow-1 Created 0.0s ✔ Container mailcowdockerized-ipv6nat-mailcow-1 Created 0.0s dependency failed to start: container mailcowdockerized-unbound-mailcow-1 is unhealthy
这是由于mailcow/unbound启动了健康检查,健康检查的逻辑是检查“1.1.1.1” “8.8.8.8” “9.9.9.9”三个dns做ping情况,并且通过本机的dns检查”mailcow.email” “github.com” “hub.docker.com”这三个域名的解析情况,如果检查不通过这个容器状态就是unhealthy。
可以通过修改mailcow.conf中SKIP_UNBOUND_HEALTHCHECK=n的健康检查参数跳过健康检查:
SKIP_UNBOUND_HEALTHCHECK=y
或者进入该容器,修改检查脚本healthcheck.sh:
[root@localhost mailcow-dockerized]# docker ps | grep unbound 08b379f97337 mailcow/unbound:1.22 "/docker-entrypoint.…" 54 minutes ago Up 54 minutes (healthy) 53/tcp, 53/udp mailcowdockerized-unbound-mailcow-1 [root@localhost mailcow-dockerized]# docker exec -it 08b379f97337 /bin/bash
将脚本中 exit 1全部修改为 exit 0,然后手动执行该脚本,等待容器状态变为healthy状态,进行执行docker compose up -d 启动命令即可。