-2

Trying to build an docker image to install Node and databases in image. Databases are installed but services are not running while trying to go for container logs ..

FROM ubuntu:lastest
RUN apt-get update && apt-get install -y curl wget gnupg && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv D68FA50FEA312927 && \
    echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | tee /etc/apt/sources.list.d/mongodb-org-3.2.list && \
    curl -sL https://deb.nodesource.com/setup_8.x | bash - && \
    apt-get update && \
    apt-get install -y nodejs mongodb-org redis-server && \
    node -v && \
    npm -v

Please do help regarding this issue, i am new to Docker.

2 Answers2

2

Best run the database containers separate, e.g. one container for mongodb and one for redis. Then connect your application container to those containers (either by links (deprecated) or by creating and sharing a network as discussed in this question. You also do not to have to start from ubuntu:latest, but can start with a node image like nodejs. Some 'orchestration', like docker-compose, can make a task of plugging these services together much easier, see this tutorial (the postgres database in the article can easily be exchanged by mongodb and redis). Also consider reading the best practices for Dockerfile writing.

tammoippen
  • 21
  • 3
0

You need to actually start mongod, e.g. like

apt-get install -y nodejs mongodb-org redis-server && \
mongod --fork && \
node -v && \
npm -v

But bear in mind that mongo should be configured first and it requires some time to spin up.

As a side note it is considered a better practice to compose individual single-purpose docker images rather than pack both database and application in a single image. Please read https://docs.docker.com/compose/overview/

Alex Blex
  • 34,704
  • 7
  • 48
  • 75