I intended to install a mongodb docker container from Docker Hub, and then insert some data into it. Obviously, a mongodb seed container is needed. So I did the following:
created a
Dockerfile
of Mongo seed container inmongo_seed/Dockerfile
and the code inDockerfile
is the following:FROM mongo:latest WORKDIR /tmp COPY data/shops.json . COPY import.sh . CMD ["/bin/bash", "-c", "source import.sh"]
The code of
import.sh
is the following:#!/bin/bash ls . mongoimport --host mongodb --db data --collection shops --file shops.json
the
shops.json
file contains the data to be imported to Mongocreated a
docker-compose.yml
file in the current working directory, and the code is the following:version: '3.4' services: mongodb: image: mongo:latest ports: - "27017:27017" container_name: mongodb mongodb_seed: build: mongodb_seed links: - mongodb
The code above successfully made the mongodb
service execute the import.sh
to import the json data - shops.json
. It works perfectly in my Ubuntu. However, when I tried to run command docker-compose up -d --build mongodb_seed
in Windows, the import of data failed with errors logs:
Attaching to linux_mongodb_seed_1
mongodb_seed_1 | ls: cannot access '.'$'\r': No such file or directory
: no such file or directory2T08:33:45.552+0000 Failed: open shops.json
mongodb_seed_1 | 2019-04-02T08:33:45.552+0000 imported 0 documents
Anyone has any ideas why it was like that? and how to fix it so that it can work in Windows as well?