Actionable docker

Note on Actionable docker

5 min read
Published December 24, 2025
Tech Notes

Actionable docker

Using docker to run packages locally.

Docker let’s you do a lot of things, here’s my tutorial on the same -

video

video

This tutorial is on actionable docker to start packages locally.

Installing Docker

Docker GUI is the easiest way to get off the ground.

You can find instructions to install docker on https://docs.docker.com/engine/install/

At the end of the installation, you need to make sure you’re able to run the following command -

Screenshot_2024-02-20_at_10.47.51_AM.png

What are we using docker for?

Docker let’s you do a lot of things.

It let’s you containerise your applications.

It let’s you run other people’s code + packages in your machine.

It let’s you run common software packages inside a container (For eg - Mongo, Postgres etc)

Screenshot_2024-02-20_at_10.57.18_AM.png

Where can we get packages from?

Just like you can push your code to Github/Gitlab.

You can push images to docker registries

Screenshot_2024-02-21_at_10.34.55_AM.png

Common commands to know

  1. docker run
  2. docker ps
  3. docker kill

Running an image

1. Running a simple image

Let’s say you wan’t to run MongoDB locally https://hub.docker.com/_/mongo

docker run mongo

Screenshot_2024-02-21_at_10.37.07_AM.png

You will notice you can’t open it in MongoDB Compass .

Screenshot_2024-02-21_at_10.38.43_AM.png

Adding a port mapping

The reason is that you haven’t added a port mapping

docker run  -p 27017:27017 mongo

Screenshot_2024-02-21_at_10.41.02_AM.png

Starting in detached mode

Adding -d will ensure it starts in the background

docker run -d -p 27017:27017 mongo

Inspecting a container

docker ps

This will show you all the containers you are running.

Stopping a container

docker kill <container_id>

Will stop the container that you are running

In the end, this is the flow of commands -

Screenshot_2024-02-21_at_10.43.18_AM.png

Common packages

Mongo

docker run -d -p 27017:27017 mongo

Postgres

docker run -e POSTGRES_PASSWORD=mysecretpassword -d -p 5432:5432 postgres

The connection string for this postgres would be

postgresql://postgres:mysecretpassword@localhost:5432/postgres

<details> <summary>Code to test it out</summary>

// Import the pg library
const { Client } = require('pg');

// Define your connection string (replace placeholders with your actual data)
const connectionString = 'postgresql://postgres:mysecretpassword@localhost:5432/postgres';

// Create a new client instance with the connection string
const client = new Client({
  connectionString: connectionString
});

// Connect to the database
client.connect(err => {
  if (err) {
    console.error('connection error', err.stack);
  } else {
    console.log('connected to the database');
  }
});

// Run a simple query (Example: Fetching the current date and time from PostgreSQL)
client.query('SELECT NOW()', (err, res) => {
  if (err) {
    console.error(err);
  } else {
    console.log(res.rows[0]);
  }

  // Close the connection
  client.end();
});

</details>