Skip to content

Commit

Permalink
Don't expose Docker ports and add .env for MongoDB.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitkonikov committed Feb 9, 2024
1 parent 975fbe1 commit 4116ff9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ echo " > docker compose down finished."

echo " > Copy .env"
cp ~/env/backend.env ~/cine/backend/.env
cp ~/env/mongodb.env ~/cine/mongodb/.env

# Start the Docker containers
echo " > Running docker compose up..."
Expand Down
9 changes: 4 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
version: '2.1'
services:
mongodb:
image: mongo:latest
ports:
- "27017:27017"
build:
context: ./mongodb
volumes:
- ~/data/db:/data/db
env_file:
- ./mongodb/.env
networks:
- gateway_app-net

Expand All @@ -15,8 +16,6 @@ services:
volumes:
- ~/_logs:/_logs
- ~/public:/public
ports:
- "3000:3000"
depends_on:
- mongodb
networks:
Expand Down
11 changes: 11 additions & 0 deletions mongodb/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM mongo:latest

# Setup env variables
ENV MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
ENV MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}

# Copy the MongoDB configuration file into the container
COPY mongod.conf /etc/mongod.conf

# Start MongoDB with authentication enabled
CMD ["mongod", "--config", "/etc/mongod.conf"]
2 changes: 2 additions & 0 deletions mongodb/mongod.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
security:
authorization: enabled

0 comments on commit 4116ff9

Please sign in to comment.