Basics of Docker

     I'm pretty fortunate as a student to have had several opportunities to use Docker, mostly those have been so I could set up a Postgres instance but recently I was able to create my own Docker image and post it on Docker Hub. My Docker image can be found here, and it will only install a simple REST API and a database for a project I am working on, so it's nothing too exciting but it was still nice to learn.


    You can get this Docker image by running 'docker push clbmrls014/team-z:tagname', using whatever label you'd like as the tag name. Once the container is up (if it doesn't start automatically you can start it with the daemon or the 'docker compose up' command). To start the Postgres database on the image you run 'docker run -p 5432:5432 -e POSTGRES_PASSWORD=password -d postgres'. To start the API you can use this command:

docker run -p 5000:80 -e ASPNETCORE_URLS="http://+:80" -e DATABASE_URL="server=kubernetes.docker.internal;user id=postgres; database=postgres; password=password" clbmrls014/team-z:tagname

    This will get the API running and you can try making a get request to 'localhost:5000/api/storeitem/getitems'. It'll return an empty list since your database is empty for now, but you can make a post request to /additem with the following JSON:

  "itemName": "string",
  "price": 0,
  "description": "string"

     Eventually this will be a bigger project, and will require authentication and will handle bad data more effectively, but for now it's been cool to play with Docker images.


Popular posts from this blog

API's in C#

Using WebRTC to build a videophone in React and TypeScript

Reviewing WPF and MVVM