Skip to main content

Posts

Showing posts from October, 2021

Running Docker Command Inside A Docker Container

But, why do we need to do this? There are several occasions that make you want to perform this action, especially if you are working on the development of a continuous delivery procedure. For example: You want to set up a closed environment (like a container) for a software testing process that requires external applications which can be run as containers. You want to build an application in a container then deploy it on another host using Docker API only, without the need for shell command execution. There are two common methods to achieve this objective. The first is by binding the Unix socket of the running Docker Engine into the container. The second is by installing a specific Docker Engine inside the container. For instance, we will run a container based on an image of Docker 20.10. We can run the following command. docker run -v /var/run/docker.sock:/var/run/docker.sock -it --rm docker:20.10 Now, you can run any  docker command inside the container that you just h...

Utilizing Worker Thread in Node.js

The worker thread module has already become a stable module on Node.js version 12. This module enables us to run multiple Node.js processes in parallel using thread. In the past, we couldn't do this easily. We probably ended up utilizing cluster or spawning child process. The difference in utilizing thread is that we have shareable resources (memory). The main and its child threads can communicate and pass the operation results directly with a concept of message passing. Child thread is usually used for distributing computation load in an application. The main thread may migrate a certain process to a child thread which is run a computational-expansive and asynchronous process. For instance, the following code shows how we can create a worker thread for a file reading process then send the result to the main thread. // module.js const { Worker, isMainThread, parentPort, workerData } = require('worker_threads'); if (isMainThread) { // if it is accessed as main threa...

Setting Up Docker Context

When we want to run a container on a remote Docker Engine host, we can utilize the context feature of Docker. Context allows us to maintain information of several Docker Engine hosts to be remotely accessed from our local Docker Engine host. Adding the record is done by running the following command. docker context create yourContextName --docker "host=ssh://user@remote.host" The connection utilizes SSH protocol so that we need to generate keys for establishing communication with the remote host. After storing the public key value on the remote host, we can spawn a new SSH agent on the current session on our host and add the private key into the agent. eval $(ssh-agent -s) cat /path/to/private/key | ssh-add - Before we can access the remote Docker API, we need to add the remote keys information to our ~/.ssh/known_hosts file by making an SSH connection for the first time or using ssh-keyscan . Now, we can access remote Docker API by specifying the context on the lo...