How to build an docker image using dockerfile which includes databases creation How to build an docker image using dockerfile which includes databases creation docker docker

How to build an docker image using dockerfile which includes databases creation


You should to expose ports for redis:

EXPOSE 6379

And please remember, that each RUN creates a new layer in your image, and you can group all shell commands in one RUN directive. It should be something like this:

FROM ubuntu:18.04RUN 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 redis-server mongodb-org redis-server && \    node -v && \    npm -v && \    mongodb -versionEXPOSE 6379

And one more thing. Docker way tell us run only one process in one container, so you should to separete your Redis, Mongo and other apps to different containers and run it with some orchestrator(such as docker-swarm or node or kubernetes) or just docker-compose.