0
0
Dockerdevops~30 mins

Database containers for local development in Docker - Mini Project: Build & Apply

Choose your learning style9 modes available
Database containers for local development
📖 Scenario: You are a developer who wants to run a database locally using Docker. This helps you test your applications without installing the database directly on your computer.
🎯 Goal: You will create a Docker command to run a PostgreSQL database container locally with a set username, password, and database name. Then, you will check if the container is running.
📋 What You'll Learn
Use the official PostgreSQL Docker image version 15
Set environment variables for POSTGRES_USER, POSTGRES_PASSWORD, and POSTGRES_DB
Map the container port 5432 to the host port 5432
Name the container 'local-postgres'
Verify the container is running using a Docker command
💡 Why This Matters
🌍 Real World
Developers often use database containers locally to avoid installing databases directly on their machines. This makes setup faster and keeps the system clean.
💼 Career
Knowing how to run and manage database containers is essential for developers and DevOps engineers to create consistent development environments and simplify testing.
Progress0 / 4 steps
1
Create the Docker run command for PostgreSQL
Write a Docker command to run a PostgreSQL container named local-postgres using the image postgres:15. Set environment variables POSTGRES_USER to devuser, POSTGRES_PASSWORD to devpass, and POSTGRES_DB to devdb. Map the container port 5432 to the host port 5432. Use the docker run command with the -d flag to run in detached mode.
Docker
Need a hint?

Use docker run -d --name local-postgres -e POSTGRES_USER=devuser -e POSTGRES_PASSWORD=devpass -e POSTGRES_DB=devdb -p 5432:5432 postgres:15

2
Check the running containers
Write a Docker command to list all running containers. Use the docker ps command.
Docker
Need a hint?

Use docker ps to see running containers.

3
Filter the running containers to find your PostgreSQL container
Write a Docker command to list running containers but only show the container named local-postgres. Use docker ps with the --filter option and filter by name=local-postgres.
Docker
Need a hint?

Use docker ps --filter "name=local-postgres" to find your container.

4
Display the container status
Write a command to show only the status of the container named local-postgres. Use docker inspect with the --format option and the Go template {{.State.Status}}.
Docker
Need a hint?

Use docker inspect --format='{{.State.Status}}' local-postgres to see if the container is running.