Skip to content

Simple .Net 5 api with mongo db intergration hosted in docker container.

Notifications You must be signed in to change notification settings

burger-mtbkr/Mongo-Api-Docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 

Repository files navigation

.Net 5.0 API using Mongo DB and Docker Compose

Prerequisites:

How to setup:

  • Clone the repo locally.
  • Using a console (powershell, bash etc) cd into the project folder
  • run the command docker-compose up
  • This will spin up two separate containers. One for the Mongo database and another for the .Net 5.0 API.
  • You can access the api on http://localhost:5000/
  • The Mongo DB runs off http://localhost:27017.
  • The docker compose uses volumes to auto create a database called ProductsDB with one collection called Products by running the /db/init_db.sh script once the container starts up.
  • This script will use the data in db.json to populate the Products collection.
  • You can use a tool such as Robo 3T: the hobbyist GUI to connect to the DB and manage the database and collections.

How to test:


Pushing to Docker Hub Repo:

If you want to push this to your own Docker Hub repository: you can follow these steps:

  1. You may need log out first docker logout then log back in using docker login.
  2. You need to include the namespace for Docker Hub to associate it with your account. The namespace is the same as your Docker Hub account name.
  3. If your image does not include your account name, you can rename it by tagging it. You can do this using docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]. e.g. docker tag dotnet-mongo-docker YOUR_DOCKERHUB_NAME/dotnet-mongo-docker:tag.
  4. You can then push your image by running this command: docker push YOUR_DOCKERHUB_NAME/dotnet-mongo-docker:tag.

Useful command:

  • docker exec -it <containername> bash - allows you to run commands in the containers. See here for more info.
  • docker tag --help - Help info to tag an image

Helpful Links:

Troubleshooting

About

Simple .Net 5 api with mongo db intergration hosted in docker container.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published