loading...

Discussion on: Running React and Node.js in one shot with Docker!

Collapse
numtostr profile image
Vikas Raj Author

docker-compose will look like this with database. Here i am using mongo.

version: "3"
services:
    database:
        container_name: awesome_database
        image: mongo
        ports:
            - 27017:27017
        volumes:
            - /data/db:/data/db
    frontend:
        container_name: awesome_web
        build:
            context: ./client
            dockerfile: Dockerfile
        image: vikasraj/awesome_web
        ports:
            - "3000:3000"
        volumes:
            - ./client:/usr/src/app
    backend:
        container_name: awesome_server
        build:
            context: ./server
            dockerfile: Dockerfile
        image: vikasraj/awesome_server
        ports:
            - "5000:5000"
        volumes:
            - ./server:/usr/src/app
        depends_on:
            - database

And make sure to change the mongo environment variable when connecting your nodejs app with the database. The database in the connection string represent the service name of your database in the docker-compose.yml.

MONGODB_URI=mongodb://database:27017/my-db

I hope this helps you.

Collapse
artoodeeto profile image
aRtoo

thank you my dude. much love on this one. last question though, lets say the database is mysql? is it the same setup as nosql? and the folder for db is level with client and server? thanks man. appreciate the help.

Thread Thread
numtostr profile image
Vikas Raj Author

I dont know know much about SQL. You can go to the dockerhub and search for mySql image. You can read more there.