<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged docker-for-beginners</title>
<link>https://coderlegion.com/tag/docker-for-beginners</link>
<description>Powered by Question2Answer</description>
<item>
<title>Docker for Beginners</title>
<link>https://coderlegion.com/28714/docker-for-beginners</link>
<description>&lt;h3 id=&quot;introduction&quot;&gt;Introduction&lt;/h3&gt;
&lt;p&gt;If you’ve ever built an application that worked perfectly on your computer but failed on another machine, then you’ve experienced one of the biggest problems in software development “inconsistent environments”.&lt;/p&gt;
&lt;p&gt;Maybe your project depended on a specific version of Python, Node.js, Java, or a database that wasn’t installed on another computer. Developers often spend hours trying to recreate the same development environment before they can even begin writing code.&lt;/p&gt;
&lt;p&gt;This is exactly the problem &lt;em&gt;Docker&lt;/em&gt; solves.&lt;/p&gt;
&lt;p&gt;Docker allows developers to package an application together with everything it needs to run, the code, libraries, dependencies, configurations, and runtime into a portable package called a container.&lt;/p&gt;
&lt;p&gt;The result is simple:&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;Build once, run anywhere.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Whether you’re running your application on Windows, macOS, Linux, a cloud server, or a teammate’s laptop, Docker helps ensure it behaves the same way.&lt;/p&gt;
&lt;h3 id=&quot;containerization&quot;&gt;Containerization&lt;/h3&gt;
&lt;p&gt;Containerization is a method of packaging software so it can run consistently across different environments.&lt;/p&gt;
&lt;p&gt;Instead of installing every dependency manually on each machine, everything the application needs is bundled together inside a container. No matter what application is inside, Docker knows how to run it consistently.&lt;/p&gt;
&lt;h3 id=&quot;docker&quot;&gt;Docker&lt;/h3&gt;
&lt;p&gt;Docker is an open source platform that helps developers build, package, distribute, and run applications inside containers.&lt;/p&gt;
&lt;p&gt;Docker provides all the tools needed to create containers, manage them, and deploy applications with minimal setup. Instead of worrying about operating systems, dependencies, or configuration differences, developers focus on writing code.&lt;/p&gt;
&lt;h3 id=&quot;docker-architecture&quot;&gt;Docker Architecture&lt;/h3&gt;
&lt;p&gt;Docker is made up of several important components. Understanding these components makes Docker much easier to learn.&lt;/p&gt;
&lt;h3 id=&quot;docker-engine&quot;&gt;Docker Engine&lt;/h3&gt;
&lt;p&gt;The Docker Engine is the core software that powers Docker. Think of Docker Engine as the “brain” of Docker.&lt;/p&gt;
&lt;p&gt;It is responsible for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Building Docker images&lt;/li&gt;
&lt;li&gt;Creating containers&lt;/li&gt;
&lt;li&gt;Running containers&lt;/li&gt;
&lt;li&gt;Managing networks&lt;/li&gt;
&lt;li&gt;Managing storage volumes&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Whenever you type a Docker command like:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker run nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Docker Engine receives the command and performs all the necessary operations behind the scenes.&lt;/p&gt;
&lt;p&gt;Without Docker Engine, Docker cannot function.&lt;/p&gt;
&lt;h2 id=&quot;docker-image&quot;&gt;Docker Image&lt;/h2&gt;
&lt;p&gt;A Docker Image is a blueprint or template used to create containers. Images are read only. You don’t run an image directly. Instead, Docker creates a container from an image.&lt;/p&gt;
&lt;p&gt;It contains:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Application code&lt;/li&gt;
&lt;li&gt;Runtime&lt;/li&gt;
&lt;li&gt;Libraries&lt;/li&gt;
&lt;li&gt;Dependencies&lt;/li&gt;
&lt;li&gt;Environment variables&lt;/li&gt;
&lt;li&gt;Configuration files&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;One Docker image can create many containers.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker pull nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This downloads the official Nginx image.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*in-bbOqK2GCmBhjQ.png&quot; alt=&quot;Docker-Desktop&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;docker-container&quot;&gt;Docker Container&lt;/h3&gt;
&lt;p&gt;A Docker Container is a running instance of a Docker image. Once an image starts running, it becomes a container. Containers are lightweight and isolated from the host operating system.&lt;/p&gt;
&lt;p&gt;You can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start containers&lt;/li&gt;
&lt;li&gt;Stop containers&lt;/li&gt;
&lt;li&gt;Restart containers&lt;/li&gt;
&lt;li&gt;Delete containers&lt;/li&gt;
&lt;li&gt;Create multiple containers from one image&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker run nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This starts a new container using the Nginx image.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*867x1u6iKCdiVdQ-.png&quot; alt=&quot;Docker-container&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;dockerfile&quot;&gt;Dockerfile&lt;/h3&gt;
&lt;p&gt;A Dockerfile is a text file containing instructions for building a Docker image. Instead of creating images manually, developers define the steps inside a Dockerfile.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;FROM node:20

WORKDIR /app

COPY . .

RUN npm install

EXPOSE 3000

CMD [&quot;npm&quot;, &quot;start&quot;]
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This tells Docker:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start from the Node.js image&lt;/li&gt;
&lt;li&gt;Create a working directory&lt;/li&gt;
&lt;li&gt;Copy project files&lt;/li&gt;
&lt;li&gt;Install dependencies&lt;/li&gt;
&lt;li&gt;Expose port 3000&lt;/li&gt;
&lt;li&gt;Start the application&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To build the image:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker build -t my-app .
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;docker-hub&quot;&gt;Docker Hub&lt;/h3&gt;
&lt;p&gt;Docker Hub is an online registry where Docker images are stored and shared. It works similarly to GitHub, but instead of storing source code, it stores Docker images.&lt;/p&gt;
&lt;p&gt;You can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Download official images&lt;/li&gt;
&lt;li&gt;Upload your own images&lt;/li&gt;
&lt;li&gt;Share images publicly or privately&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Popular images include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;nginx, mysql, postgres, redis, node, ubuntu, python,&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;To download an image:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker pull nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*ycT87QX0JrAO8zcm.png&quot; alt=&quot;Docker-Hub&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;docker-ports&quot;&gt;Docker Ports&lt;/h3&gt;
&lt;p&gt;Applications inside containers run in their own isolated environment. To access them from your computer, Docker maps container ports to ports on the host machine.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker run -p 8080:80 nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Port 80 is inside the container.&lt;/li&gt;
&lt;li&gt;Port 8080 is on your computer.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Visiting:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;http://localhost:8080
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;will display the Nginx web page.&lt;/p&gt;
&lt;h3 id=&quot;docker-volumes-optional-but-useful-&quot;&gt;Docker Volumes (Optional but Useful)&lt;/h3&gt;
&lt;p&gt;Containers are temporary. If a container is deleted, its data is also deleted unless it is stored in a Docker Volume. Volumes allow data to persist.&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker volume create mydata
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;installing-docker&quot;&gt;Installing Docker&lt;/h3&gt;
&lt;p&gt;The installation process depends on your operating system.&lt;/p&gt;
&lt;h3 id=&quot;windows&quot;&gt;Windows&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Download Desktop Docker&lt;/li&gt;
&lt;li&gt;Run the installer.&lt;/li&gt;
&lt;li&gt;Enable WSL 2 if prompted.&lt;/li&gt;
&lt;li&gt;Restart your computer.&lt;/li&gt;
&lt;li&gt;Open Docker Desktop.&lt;/li&gt;
&lt;li&gt;Wait until Docker starts successfully.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Verify installation:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker --version or docker version
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*aQsCnX7LYfpGybPS.png&quot; alt=&quot;Docker-Version&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;macos&quot;&gt;macOS&lt;/h3&gt;
&lt;ol&gt;
&lt;li&gt;Download Docker Desktop for macOS.&lt;/li&gt;
&lt;li&gt;Install the application.&lt;/li&gt;
&lt;li&gt;Launch Docker Desktop.&lt;/li&gt;
&lt;li&gt;Wait until Docker finishes starting.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Verify:&lt;/p&gt;
&lt;p&gt;docker --version&lt;/p&gt;
&lt;h3 id=&quot;ubuntu-linux&quot;&gt;Ubuntu Linux&lt;/h3&gt;
&lt;p&gt;Update packages:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo apt update
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Install Docker:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo apt install docker.io
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Enable Docker:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;sudo systemctl enable docker
sudo systemctl start docker
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Verify:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker --version
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Run without sudo (optional):&lt;/p&gt;
&lt;p&gt;sudo usermod -aG docker $USER&lt;br&gt;
Then log out and log back in.&lt;/p&gt;
&lt;h3 id=&quot;your-first-docker-deployment&quot;&gt;Your First Docker Deployment&lt;/h3&gt;
&lt;p&gt;Let’s deploy a simple static web landing page using Docker.&lt;/p&gt;
&lt;h3 id=&quot;step-1-search-the-docker-hub-for-an-image&quot;&gt;Step 1: search the docker hub for an image&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;docker pull nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Docker downloads the latest Nginx image from Docker Hub.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*sK34AhJ1XXUzrhgd.png&quot; alt=&quot;Docker-image&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;step-2-start-a-container&quot;&gt;Step 2: Start a Container&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;docker run -d -p 8088:80 --name welcome-to-docker docker/welcome-to-docker
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Here’s what each option means:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;-d runs the container in the background (detached mode).&lt;/li&gt;
&lt;li&gt;-p 8080:80 maps your computer's port 8080 to the container's port 80.&lt;/li&gt;
&lt;li&gt;--name welcome-to-docker gives the container an easy name to remember .&lt;/li&gt;
&lt;li&gt;docker/welcome-to-docker is the image used to create the container.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*lADqo8zJuXJwpR6S.png&quot; alt=&quot;docker/welcome-to-docker&quot;&gt;&lt;/p&gt;
&lt;h3 id=&quot;step-3-verify-the-container-is-running&quot;&gt;Step 3: Verify the Container is Running&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;docker ps
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should see your running container listed.&lt;/p&gt;
&lt;p&gt;Press enter or click to view image in full size&lt;/p&gt;
&lt;h3 id=&quot;step-4-open-your-browser&quot;&gt;Step 4: Open Your Browser&lt;/h3&gt;
&lt;p&gt;Visit:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;http://localhost:8088
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You should see the congratulation page.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://coderlegion.com/?qa=blob&amp;amp;qa_blobid=2333014123831853996&quot; alt=&quot;&quot;&gt;&lt;img src=&quot;https://miro.medium.com/v2/resize:fit:828/format:webp/0*bL3ZSWheU3y3PFQS.png&quot; alt=&quot;&quot;&gt;&lt;/p&gt;
&lt;p&gt;Congratulations you’ve deployed your first application using Docker!&lt;/p&gt;
&lt;p&gt;Step 5: Stop the Container&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;docker stop my-nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-6-start-it-again&quot;&gt;Step 6: Start It Again&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;docker start my-nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;step-7-remove-the-container&quot;&gt;Step 7: Remove the Container&lt;/h3&gt;
&lt;pre&gt;&lt;code&gt;docker rm my-nginx
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If the container is still running, stop it first.&lt;/p&gt;
&lt;h3 id=&quot;summary&quot;&gt;Summary&lt;/h3&gt;
&lt;p&gt;Through containerization, anyone can package applications and their dependencies into portable, lightweight containers that run consistently across different environments. With these fundamentals in place, you’re ready to explore more advanced Docker topics such as Docker Compose, custom image creation, networking, volumes, and multi-container applications.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/28714/docker-for-beginners</guid>
<pubDate>Sat, 26 Sep 2026 11:43:18 +0000</pubDate>
</item>
</channel>
</rss>