Replies: 1 comment
-
Our biggest problem was to configure a database up and running that the application could connect to. So, I created a very simple docker-compose file to set up and tear down easily a database that the application can connect to. Instructions.You need Docker and Docker-compose. If you are on Mac or Windows, when installing Docker, you automatically get Docker-compose with it. Once this is done you will need a file called docker-compose.yaml in the base directory. Create the file, and copy paste the following content into it: version: '3'
services:
mongodb:
image: mongo:3.6.23
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: oui
MONGO_INITDB_ROOT_PASSWORD: password You can select any username and password you'd like.
If you changed the username and password in the docker-compose.yaml file, match them accordingly in the env file. docker-compose up Once you do not need the database anymore, run docker-compose down |
Beta Was this translation helpful? Give feedback.
-
During the first coding evening, we realized that setting up the development environment was quite cumbersome and not that beginner-friendly. One idea that came to mind was to build a Docker image with the development environment ready. I am starting a discussion here about ideas that came to mind, please share your thoughts about them or bring up more solutions.
1. Application + database into one Dockerfile.
We could build an image based on node.js and install a mongo db database in it. This would makes the deployment on local environment the easiest possible: download the image, the app is running. Also, if the image is stored in a private repository, then environment variable can be automatically configured. I see 3 disadvantages though:
2. Application and database in different Dockerfiles, docker-compose to set up environment.
This would solve the problem of image size + would follow best practices to break down the application into smaller pieces. Create a docker for the application, and pull a MongoDB image. Running a
docker-compose up
would setup the environment and work out of the box.Advantages
docker-compose up
anddocker-compose down
would make the environment spin-up and tear-down very easy.Drawbacks
3. Only use database container.
In this scenario, the code is still downloaded locally, but we provide an image for MongoDB, so we do not rely on external services. A developer could download the image, and by setting the right URL in .env files, have access to it. It can also be spin-up and tear-down with ease.
Advantages
Drawbacks
Please let me know what you think about this :)
Beta Was this translation helpful? Give feedback.
All reactions