docker部署失败


#1

我下载了docker-compose.yml,然后使用docker-compose up -d,然后使用docker logs
发现以下错误:

waiting for mysql server to be ready: %s (2005, “Unknown MySQL server host ‘db’ (0)”)

请问该如何修复该问题?


#2

这个日志信息理论上都会出现几次的,这是因为要等待mysql容器启动,你要等待几分钟,这个会自动处理的,最终应该是没有问题的


#3

我后来重新学了一遍docker的网络,发现这应该是我改了docker-compose.yml的网络配置导致的。
因为我不想使用docker帮我创建的user defined network。所以改成了network_mode: host。
所以3个容器启动后,估计是没利用到docker embedded dns,因而seafile这个container并不知道如何去连接db这个container,故导致了找不到数据库的故障。后来我把网络改回原来默认的seafile-net,就可以正常启动了。

然而,我还是希望docker-compose能够利用我手工创建的user defined network(bridge),这样我才能指定网段。所以又改了docker-compose.yml,当然这是后话了。

不管如何,这个故障的原因就是我所推测的,将docker-compose.yml的网络改成host之后,各个container之间无法找到对方,导致了数据库连接失败。


#4

docker-compose.yml 示例里说暴露 80 端口,但我登录到docker里面怎么发现seahub 运行在8000端口,所以我把端口改成 8000:8000了

运行 docker-compose up -d 后发现服务都起来了,但是在浏览器里输入file.mycompany.com:8000 并不能访问。

我··docker exec -it 到 seafile container里面去, wget 127.0.0.1:8000’ 是可以拿到一个index.html页面,看起来是一个登陆页。但为什么在外面用域名不能访问呢?

我是完全按照文档https://cloud.seafile.com/published/seafile-manual-cn/docker/%E7%94%A8Docker%E9%83%A8%E7%BD%B2Seafile.md 来的,看起来不是文档有问题就是镜像有问题,帮忙指点一下?

version: '2.0'
services:
  db:
    image: mariadb:10.1
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=mycompany  # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
    volumes:
      - /opt/seafile-mysql/db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    networks:
      - seafile-net

  memcached:
    image: memcached:1.5.6
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net
          
  seafile:
    image: seafileltd/seafile-mc:latest
    container_name: seafile
    ports:
      - "8000:8000"
      - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - /opt/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=mycompany  # Requested, the value shuold be root's password of MySQL service.
   #   - TIME_ZONE=Asia/Shanghai # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=me@mycompany.com # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=asecret     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=true   # Whether to use https or not.
      - SEAFILE_SERVER_HOSTNAME=file.mycompany.com # Specifies your host name if https is enabled.
    depends_on:
      - db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

运行 docker-compose up -d后发现服务都起来了,但是在浏览器里输入file.mycompany.com:8000 并不能访问。

我··docker exec -it 到 seafile container里面去,wget 127.0.0.1:8000’ 是可以拿到一个index.html页面,看起来是一个登陆页。但为什么在外面用域名不能访问呢?

[root@iz2ze78t84wkep9q8jsf4hz seafiles]# docker ps
CONTAINER ID        IMAGE                          COMMAND                  CREATED             STATUS              PORTS                            NAMES
bae82335eca9        seafileltd/seafile-mc:latest   "/sbin/my_init -- ..."   3 hours ago         Up 3 hours          80/tcp, 0.0.0.0:8000->8000/tcp   seafile
97389e118d18        mariadb:10.1                   "docker-entrypoint..."   3 hours ago         Up 3 hours          3306/tcp                         seafile-mysql
7e248db3b46c        memcached:1.5.6                "memcached -m 256"       3 hours ago         Up 3 hours          11211/tcp                        seafile-memcached
[root@iz2ze78t84wkep9q8jsf4hz seafiles]# docker logs bae82335eca9
*** Running /etc/my_init.d/01_create_data_links.sh...
*** Running /etc/my_init.d/10_syslog-ng.init...
Aug  1 07:03:28 bae82335eca9 syslog-ng[19]: syslog-ng starting up; version='3.13.2'
*** Booting runit daemon...
*** Runit started as PID 27
*** Running /scripts/start.py...
Aug  1 07:03:29 bae82335eca9 cron[33]: (CRON) INFO (pidfile fd = 3)
Aug  1 07:03:29 bae82335eca9 cron[33]: (CRON) INFO (Running @reboot jobs)
[2019-08-01 07:03:46] Now running setup-seafile-mysql.py in auto mode.
Checking python on this machine ...
  Checking python module: python-mysqldb ... Done.
done
Successly create configuration dir /opt/seafile/ccnet.
Done.
verifying password of user root ...  done
---------------------------------
This is your configuration
---------------------------------
    server name:            seafile
    server ip/domain:       files.bimsop.com
    seafile data dir:       /opt/seafile/seafile-data
    fileserver port:        8082
    database:               create new
    ccnet database:         ccnet_db
    seafile database:       seafile_db
    seahub database:        seahub_db
    database user:          seafile
Generating ccnet configuration ...
Generating seafile configuration ...
done
Generating seahub configuration ...
----------------------------------------
Now creating ccnet database tables ...
----------------------------------------
----------------------------------------
Now creating seafile database tables ...
----------------------------------------
----------------------------------------
Now creating seahub database tables ...
----------------------------------------
creating seafile-server-latest symbolic link ...  done
-----------------------------------------------------------------
Your seafile server configuration has been finished successfully.
-----------------------------------------------------------------
run seafile server:     ./seafile.sh { start | stop | restart }
run seahub  server:     ./seahub.sh  { start <port> | stop | restart <port> }
-----------------------------------------------------------------
If you are behind a firewall, remember to allow input/output of these tcp ports:
-----------------------------------------------------------------
port of seafile fileserver:   8082
port of seahub:               8000
When problems occur, Refer to
        https://github.com/haiwen/seafile/wiki
for information.
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' (111)")
[08/01/2019 07:03:53][upgrade]: The container was recreated, running minor-upgrade.sh to fix the media symlinks
[08/01/2019 07:03:53][upgrade]: Running script /opt/seafile/seafile-server-7.0.3/upgrade/minor-upgrade.sh
[2019-08-01 07:03:53] Updating version stamp
-------------------------------------------------------------
This script would do the minor upgrade for you.
Press [ENTER] to contiune
-------------------------------------------------------------
------------------------------
migrating avatars ...
DONE
------------------------------
updating seafile-server-latest symbolic link to /opt/seafile/seafile-server-7.0.3 ...
DONE
------------------------------
[08/01/19 07:03:53] ../common/session.c(132): using config file /opt/seafile/conf/ccnet.conf
Starting seafile server, please wait ...
** Message: seafile-controller.c(718): No seafevents.
Seafile server started
Done.
**Starting seahub at port 8000 ...**
----------------------------------------
Successfully created seafile admin
----------------------------------------
Seahub is started
Done.
Aug  1 07:17:01 bae82335eca9 CRON[1424]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  1 08:17:01 bae82335eca9 CRON[7165]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Aug  1 09:17:01 bae82335eca9 CRON[12905]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
[root@iz2ze78t84wkep9q8jsf4hz seafiles]#


#5
root@2e4e4abd3a57:/opt/seafile# lsof -i -P | grep 80
nginx      29 root    6u  IPv4 5662073      0t0  TCP *:80 (LISTEN)
seaf-serv 142 root   19u  IPv4 5662174      0t0  TCP *:8082 (LISTEN)
python2.7 175 root    7u  IPv4 5667847      0t0  TCP localhost:8000 (LISTEN)
python2.7 181 root    7u  IPv4 5667847      0t0  TCP localhost:8000 (LISTEN)
python2.7 182 root    7u  IPv4 5667847      0t0  TCP localhost:8000 (LISTEN)

1、80端口是nginx监听的,担任反向代理的功能。请求经由nginx再转给python的web server(监听8000),所以,你不需要将80改成8000。
2、127.0.0.1:8000仅监听本地loopback地址,根本无法响应外界的请求。这是网络方面的基础知识。
3、lsof、ss都是你的好朋友,要善于利用。