To set up the database servers using Docker Compose, follow these steps:
-
Install Docker and Docker Compose: Ensure you have Docker and Docker Compose installed on your machine. You can download them from Docker's official website.
-
Clone the Repository: Clone this repository to your local machine using:
git clone https://github.com/yourusername/database_servers.git cd database_servers
-
Create a
.env
File: Create a.env
file in the root directory of the project and add the necessary environment variables. For example:POSTGRES_USER=yourusername POSTGRES_PASSWORD=yourpassword POSTGRES_DB=yourdatabase
-
Run Docker Compose: Use the following command to start the services defined in the
docker-compose.yml
file:docker-compose up -d
-
Access the Services: Once the services are up and running, you can access them using the appropriate ports defined in the
docker-compose.yml
file. -
Stop the Services: To stop the services, run:
docker-compose down
The following services are included in the docker-compose.yml
file:
- PostgreSQL: A powerful, open-source object-relational database system.
- MySQL: An open-source relational database management system.
Here is an example of what your docker-compose.yml
file might look like:
version: '3.8'
services:
postgres:
image: postgres:latest
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
mysql:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
volumes:
postgres_data:
mysql_data:
If you encounter any issues, check the logs of the services using:
docker-compose logs
For more detailed information, refer to the official documentation of Docker and Docker Compose.