We have talked about docker a few times in the past. Most recently, we talked about it in the context of running Ollama. For today’s post, I wanted to talk about how to turn your code into a docker container that you can run somewhere.
What is Docker
Docker provides the ability to package and run an application in a loosely isolated environment called a container. Docker containers can be deployed to just about any machine without any compatibility issues so your software stays system agnostic, making software simpler to use, less work to develop, and easier to maintain and deploy.
Once upon a time, a web application would be run on a physical piece of hardware that is running an operating system like Linux or Windows and then virtualization became a thing. Virtual machines access the hardware of a physical machine through a hypervisor. The host machine has an operating system (Ubuntu, Windows, MacOS, etc) and a hypervisor. Each virtual machine has an operating system of its own, binaries and libraries, and the actual web app. When using containers, the host machine has an operating system and a container engine but the containers only have binaries and libraries and the actual web app (no guest OS is necessary).
A dockerfile is needed to create an image and a container is the result of running an image. Today I am going to show how to go from a basic web app to a running docker container.
A Basic Node Example
If we are going to be dockerizing a web app, we need a web app to dockerize. In yesterday’s demo on how to pass an array as a property into a web component, we looked at three ways to turn an array into an unordered list. I figured that we could do the same with today’s demo.
In the above Node app, we are setting const items as being an array, using <a href="https://www.w3schools.com/nodejs/met_http_createserver.asp">createServer()</a> to create a new HTTP server, and then we are setting it to listen on port 8080. If you save the file locally as app.js, assuming that you have Node installed on your machine, you can run node app.js from the terminal to start the server.
You will notice that it also includes the line EXPOSE 8080, to expose port 8080 but as you will see below, it is more for documentation purposes than anything else.
Creating a Dockerignore
If you are familiar with git, you likely know what a .gitignore file is. A .dockerignore file does something similar. A .dockerignore is a configuration file that describes files and directories that you want to exclude when building a Docker image. Usually, you put the Dockerfile in the root directory of your project, but there may be many files in the root directory that are not related to the Docker image or that you do not want to include. .dockerignore is used to specify unwanted files and not include them in the Docker image.
Building a Docker Image
Now that you have what you are dockerizing, a Dockerfile, and a .dockerignore, you can simply build by running docker build . in the terminal.
If you want to aid in maintainability a little, you can add -t [image name] to the build command. When you run docker build -t node-app . in the terminal, it looks like this …
As I said above, an image becomes a container when you execute it. You can execute it by running docker run -d -p 8080:8080 6cced9894e8c where -d runs it as a daemon (a background process) and -p [port number]:[port number] tells the container what port to give it on the host machine. The 6cced9894e8c hash is the “Image ID” value from when I ran docker images above. If you tagged the image in the above step, you can use that value instead of the hash, though.
If you run docker ps after starting the container, you can verify that it is running. Go to http://localhost:8080/ and witness the splendor (now running in a docker container).
Ok peeps, we're 4 months into 2024 and I've been without work this whole time so we're going to try this again. If you know of any senior software engineering positions that are actually being hired for, please drop them below.
I have 12 cumulative years of experience, so that shouldn't be an issue, and I know most of the languages in use nowadays well enough to be dangerous, but I am extremely proficient in TypeScript, Python, and Ruby. What I'd rather do more than anything though is have an opportunity to use Go professionally.
Grund 409638045983 warum ich dieses ganze #nodejs Universum verachte:
Habe Code - nicht meiner, kann daran nichts ändern.
Code hat sich seit 7 Monaten nicht geändert.
Vor 7 Monaten ist die Pipeline gelaufen und hat ein Image erfolgreich gebaut.
Heute läuft die Pipeline nicht mehr, weil sich irgendeine Abhängigkeit anders verhält als vor 7 Montaten.
Und nu?
Ja, bleiben diese 9,8er CVEs halt drin in dem Image, weil neu Bauen geht nicht.
I'm finally at the point where I have to start working on perhaps the main feature of my programming language Squarepants: the ability to compile to GPU Shaders.
The most attractive target would be #SpirV which is an intermediate representation that works almost everywhere... Except on browsers, and only because #Apple didn't want to give control of the standard to the group that develops SpirV.
Instead, Apple imposed #WGSL , which is a language instead than an intermediate representation, so it's a pain in the ass to target and will end up with the same problem as #javascript .
At some point there will be translators from SpirV to WGSL, but I can't rely on those now.
So, what am I going to target?
Right now Squarepants compiles to javascript, so can run easily in both browsers and #nodejs.
There is a project to run SpirV (via Vulkan) on node, but has been dead for years, which means that if I want to compile to a native application, I need Squarepants to compile to C or LLVM first.
OTOH if I go through the square-peg-in-round-hole and target WGSL, then I can target browsers.
Did you know that you don't need to commit to an entire @agregore browser to make use of it's tech? If you already have #nodejs installed you can run agregore-compatible #JavaScript modules from your cli over any protocol supported by the browser. (e.g. #IPFS or #gemini )
npx agregore run hyper://blog.mauve.moe/example.js
With this you can share #p2p code between applications and command line utilities.
A critical vulnerability, named BatBadBut, was discovered in the Rust programming language, affecting not just Rust but also Erlang, Go, Python, Ruby, and potentially others. This vulnerability, with a severity score of 10/10, could allow attackers to execute arbitrary commands on Windows systems by exploiting how Rust handles batch files. The issue arises from Rust's standard library improperly escaping arguments when invoking batch files on Windows, leading to potential command injection. The vulnerability has been addressed with a fix in Rust version 1.77.2, which developers are urged to update to. Other programming languages and systems, including Node.js, PHP, and Java, are also affected and are working on patches.
As I've noticed it's #PortfolioDay and have seen some wonderful artwork posted by people, as a programmer, I'd like to share a project I made, a command line time tracker with the purely textual interface.
Since I spent a good deal of time designing the textual output and UX I figure it's akin to art.
The interface is natural language input of times and dates representing when you start and end tasks.
Completed setup of a #refurbed small Windows PC today and remoted into it from my MacBook to #debug some #nodejs code that was failing its windows tests on GitHub Actions
Is almost 20 years since Windows was my primary dev machine – it feels so alien nowadays when all my dev work is centered around git and cli-tools
Ever worked on #nodejs projects locally and wished for a more standardized, production-like experience for your team? Try @ddev! I walk you through setting your local up with #docker#containers in my latest article on @lullabot
A cybersecurity researcher finds that 20% of software packages recommended by GPT-4 are fake, so he builds one that 15,000 code bases already depend on, to prevent some hacker from writing a malware version.
Disaster averted in this case, but there aren't enough fingers to plug all the AI-generated holes 😬
Online Interview Questions : Top interview questions and... (www.onlineinterviewquestions.com)
Prepare Top Interview Questions Online on CorePHP, CakePHP, MySQL, Zend Framework, jQuery, NodeJS, Laravel, Angularjs, Angular 2, ReactJs, Vuejs, JSF, Struct, CSS3, HTML5, JavaScript, JSON, MAVEN, CakePHP, ReactJs