docker 从3.4升级和/或数据恢复到3.6后与Mongodb的连接问题

qv7cva1a  于 2023-04-20  发布在  Docker
关注(0)|答案(1)|浏览(129)

我在用Docker。
我正在尝试为我的本地机器更新mongo版本。我注意到,当我从版本(从3.4到3.6在docker-compose.yml)更新镜像时,尽管mongo镜像启动,但没有客户端(我的应用程序和studio 3 T)可以连接到新镜像(获得连接超时)。
我尝试的另一种方法是创建两个新的干净容器(一个版本3.4,另一个版本3.6,两者具有相同的凭据),并从3.4获取转储,将其复制到3.6容器并进行还原。还原工作,但当我尝试使用studio 3 T连接到3.6数据库时,我再次遇到连接问题。
下面是我的docker-compose.yml文件:

version: '3.9'
services:
  mongo:
    image: mongo:3.4
    ports:
      - 27020:27017
    volumes:
      - mongo-test:/data/db
  mongo-new:
    image: mongo:3.6
    ports:
      - 27021:27017
    volumes:
      - mongo-test-new:/data/db
volumes:
  mongo-test:
  mongo-test-new:

我的垃圾堆里有一个小文件。
我很迷茫。为什么这么简单的事情就不可能发生呢?

**编辑1:**错误日志如下:

Connection failed.

SERVER [localhost:27021] (Type: UNKNOWN) 
|_/ Connection error (MongoSocketReadException): Prematurely reached end of stream

Details:
Timed out after 5000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27021, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadException: Prematurely reached end of stream}}]

编辑2:添加docker日志

test-mongo-new-1  | 2023-04-17T02:58:54.545+0000 I CONTROL  [initandlisten] MongoDB starting : pid=7 port=27017 dbpath=/data/db 64-bit host=f7bff9e5afa8
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] db version v3.6.23
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] git version: d352e6a4764659e0d0350ce77279de3c1f243e5c
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] allocator: tcmalloc
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] modules: none
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten] build environment:
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
test-mongo-new-1  | 2023-04-17T02:58:54.546+0000 I CONTROL  [initandlisten]     distarch: x86_64
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I CONTROL  [initandlisten]     target_arch: x86_64
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I CONTROL  [initandlisten] options: {}
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 W -        [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 W STORAGE  [initandlisten] Recovering data from the last clean checkpoint.
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
test-mongo-new-1  | 2023-04-17T02:58:54.547+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=3417M,cache_overflow=(file_max=0M),session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),compatibility=(release="3.0",require_max="3.0"),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
test-mongo-new-1  | 2023-04-17T02:58:55.610+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:610320][7:0x7f24b4718a40], txn-recover: Main recovery loop: starting at 3/4480
test-mongo-new-1  | 2023-04-17T02:58:55.611+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:611263][7:0x7f24b4718a40], txn-recover: Recovering log 3 through 4
test-mongo-new-1  | 2023-04-17T02:58:55.696+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:696453][7:0x7f24b4718a40], txn-recover: Recovering log 4 through 4
test-mongo-new-1  | 2023-04-17T02:58:55.744+0000 I STORAGE  [initandlisten] WiredTiger message [1681700335:744249][7:0x7f24b4718a40], txn-recover: Set global recovery timestamp: 0
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] ** WARNING: This server is bound to localhost.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          Remote systems will be unable to connect to this server. 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          Start the server with --bind_ip <address> to specify which IP 
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          addresses it should serve responses from, or with --bind_ip_all to
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          bind to all interfaces. If this behavior is desired, start the
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] **          server with --bind_ip 127.0.0.1 to disable this warning.
test-mongo-new-1  | 2023-04-17T02:58:55.762+0000 I CONTROL  [initandlisten] 
test-mongo-new-1  | 2023-04-17T02:58:55.772+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
test-mongo-new-1  | 2023-04-17T02:58:55.773+0000 I NETWORK  [initandlisten] listening via socket bound to 127.0.0.1
test-mongo-new-1  | 2023-04-17T02:58:55.773+0000 I NETWORK  [initandlisten] listening via socket bound to /tmp/mongodb-27017.sock
test-mongo-new-1  | 2023-04-17T02:58:55.773+0000 I NETWORK  [initandlisten] waiting for connections on port 27017
test-mongo-new-1  | 2023-04-17T02:58:56.011+0000 I FTDC     [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
unftdfkk

unftdfkk1#

线索就在集装箱日志里。。

WARNING: This server is bound to localhost.
         Remote systems will be unable to connect to this server.

参见Compatibility Changes in MongoDB 3.6
当仅绑定到localhost时,这些MongoDB 3.6二进制文件只能接受来自运行在同一台机器上的客户端(包括mongo shell,副本集和分片集群部署中的其他成员)的连接。远程客户端无法连接到仅绑定到localhost的二进制文件。
不幸的是,这意味着默认情况下无法从容器外部连接。
最简单的修复方法是通过添加command后缀来绑定所有可用的网络接口

mongo-new:
  image: mongo:3.6
  ports:
    - 27021:27017
  volumes:
    - mongo-test-new:/data/db
  command: --bind_ip_all

请参见不使用配置文件自定义配置

相关问题