This project is a Dockerized full-stack web application that uses Node.js for the backend, React for the frontend, MongoDB as the database and Cypress as e2e library. The purpose of this project is to create a fully containerized development and testing environment, where you can run a single command to get it up and running.
- Features
- Requirements
- Getting Started
- Volumes and Mounts
- Stopping and Restarting Containers
- Run Cypress tests
- Fullstack setup: React frontend, Node.js backend, and MongoDB database and Cypress as e2e framework
- Data persistence using Docker volumes, ensuring data is not lost when containers are stopped.
- Hot-reloading through mount binding, reflecting any code changes without needing to rebuild containers.
- Simple orchestration using
docker-compose.
Before you can run this project, ensure you have the following installed:
- Docker: Install Docker
- Docker Compose: Comes bundled with Docker Desktop or install it separately.
git clone https://github.com/TStefann/Docker.gitOnce everything is set up, you can bring up the entire stack using Docker Compose:
docker-compose up -dThis will start the Node.js server, the React frontend, and the MongoDB database.
-
Frontend: Open your browser and go to http://localhost:3000
-
Backend API: Go to http://localhost:8080
-
Data Persistence: The application is configured with Docker volumes to ensure your MongoDB data persists even when the container is shut down. This is defined in the
docker-compose.ymlfile.volumes: - data:/data/db
-
Code Synchronization: Mount binding is used to sync your local code with the container, so changes made to your local files are reflected inside the container without needing a rebuild.
For example:
volumes: - ./backend:/app - ./frontend/src:/app/src
To stop the containers, run:
docker-compose downTo bring the containers back up again:
docker-compose upTo remove all containers, volumes, and networks, use:
docker-compose down --volumesdocker run --rm --network host -it -v ./e2e:/e2e -w /e2e cypress/included This will mount the host directory e2e/cypress and the file e2e/cypress.config.js as volumes within the container. This means that:
- anything that Cypress writes to these folders (e.g., screenshots, videos) appears also on the Docker host's filesystem
- any change that the developer applies to Cypress files on the host machine immediately takes effect within the e2e container (no docker rebuild required).