简体   繁体   中英

Import data on mongodb from docker-compose

I want to import data in my mongodb database with a docker-compose but i don't found a solution. This is an idea that i get somewhere but that does not work. If someone see a better solution or just fix this solution , i take :).Thank you

./docker-compose.yml

db:
  image: mongo
  ports:
   - 27018:27017

dbseed:
  build: ./dbseed
  links:
    - db

app:
  build: .
  links:
   - db:db
  ports:
   -8080:8080
   -8181:8181

dbseed/new_climat_final.json

[
  {
    "name": "Joe Smith",
    "email": "jsmith@gmail.com",
    "age": 40,
    "admin": false
  },
  {
    "name": "Jen Ford",
    "email": "jford@gmail.com",
    "age": 45,
    "admin": true
  }
]

dbseed/Dockerfile

FROM mongo

COPY new_climat_final.json /new_climat_final.json

CMD mongoimport --host db --db hpApiDev --collection coll --type json --file /new_climat_final.json --jsonArray

No error but no data in my mongodb database :/

Cf : docker-compose logs

Attaching to dockernode_db_1, dockernode_dbseed_1
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=d48c97fd7ca5
dbseed_1 | 2015-12-21T17:42:46.609+0000 Failed: open /new_climat_final.json: no such file or directory
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] db version v3.2.0
dbseed_1 | 2015-12-21T17:42:46.609+0000 imported 0 documents
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1e 11 Feb 2013
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] allocator: tcmalloc
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] modules: none
db_1     | 2015-12-22T00:57:46.629+0000 I CONTROL  [initandlisten] build environment:
db_1     | 2015-12-22T00:57:46.630+0000 I CONTROL  [initandlisten]     distmod: debian71
db_1     | 2015-12-22T00:57:46.630+0000 I CONTROL  [initandlisten]     distarch: x86_64
db_1     | 2015-12-22T00:57:46.630+0000 I CONTROL  [initandlisten]     target_arch: x86_64
db_1     | 2015-12-22T00:57:46.630+0000 I CONTROL  [initandlisten] options: {}
db_1     | 2015-12-22T00:57:46.642+0000 I -        [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
db_1     | 2015-12-22T00:57:46.643+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
db_1     | 2015-12-22T00:57:47.829+0000 I CONTROL  [initandlisten] 
db_1     | 2015-12-22T00:57:47.830+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
db_1     | 2015-12-22T00:57:47.830+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
db_1     | 2015-12-22T00:57:47.830+0000 I CONTROL  [initandlisten] 
db_1     | 2015-12-22T00:57:47.830+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
db_1     | 2015-12-22T00:57:47.830+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
db_1     | 2015-12-22T00:57:47.830+0000 I CONTROL  [initandlisten] 
db_1     | 2015-12-22T00:57:47.833+0000 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
db_1     | 2015-12-22T00:57:47.833+0000 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
db_1     | 2015-12-22T00:57:47.835+0000 I NETWORK  [initandlisten] waiting for connections on port 27017

Edit full path: build: /path/to/dbseed

I'm not sure why it could not find /new_climat_final.json file. Error:

dbseed_1 | 2015-12-21T17:42:46.609+0000 Failed: open /new_climat_final.json: no such file or directory

But you can specify port when you run

CMD: CMD mongoimport --host db --port 27018 --db hpApiDev --collection coll --type json --file /new_climat_final.json --jsonArray

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM