Create a Docker Container using Cursor
Create a PostgreSQL Docker container using natural language in Cursor.
Project work by Ron Obi Nwumeh on NextWork.
Introducing Today's Project!
In this project, I'm going to use the AI power of cursor to build and and run a database back end and front end all from docker containers.
Key tools and concepts
The key tools I used include Cursor, Docker Desktop, Docker MCP. Key concepts I learnt include database administration, container networking, prompt engineering.
Challenges and wins
This project took me approximately 2 hours. I took the scenic route and learned quite a bit. Doing it again would take maybe 30min.
Why I did this project
I did this project today to get hands on with containers and databases and AI tools. I liked using Cursor on my laptop, it makes it easy to build and learn a lot. The agent fixed issues and showed all it's steps and commands making it easy to follow along each micro step and think more big picture. I'm curious to compare it to similar features in other code editors like vscode. These tools could really make building and learner easier and more fun for everyone from newcomers to the more experienced.
Setting Up Cursor and Docker Desktop
Getting our tools together. Cursor is a is a relatively large download at about 1 gigabyte.
Why Docker containers?
We will build inside of Docker containers. Containers are useful because they are a standardized environment, eliminating compatibility issues, and they also efficiently use our computer hardware resources.
Connecting Cursor to Docker with MCP
In this step, I'm enabling the Docker MCP (model context protocol) it's essentially software which lets Cursor Talk to Docker Desktop and manage our containers for us.
Installing Python and uv
Python provides the environment for these MCP servers to run, and uv is used to manage their dependencies. uv is a high performance package manager for python that works 10-100X faster than pip which is the default package manager. This makes uv better suited for the demands of Docker MCP.
What the Docker MCP can do
It allows Cursor to create and manage containers for me. All I have to do is provide instructions to the chat agent in cursor. For example I will tell it the type of database container services I want it to run and it will create them for me, instead of me having to type each of the required commands myself. This allows me to focus more on high level tasks.
Creating My First PostgreSQL Container
With Cursor, I will use easy natural language to prompt engineer and create my PostgreSQL container database.
Verifying the container
I verified my container by checking Docker Desktop where I can see a green indicator.
Orchestrating Multiple Containers with Docker Compose
In this step, I'm setting up a way to access my new database and view its contents from my web browser. From Docker Compose, I create a new container to run Adminer, a software that will connect to my postgreSQL database and create a web interface visible from my browser.
Setting up the docker-compose.yml file
I created a docker-compose.yml file that defines the containers I want. The two containers running are PostgreSQL and Adminer.
Accessing the database in the browser
I verified my database by logging into Adminer at localhost:8080. Currently empty but this is where I would see my database contents.
Monitoring Container Logs
In this project extension, I'm going to take a look at my container logs by simply asking Cursor.
What I learned from the logs
With a simple prompt. It's great!