Docker for Absolute Beginners

Introduction to Docker

What is Docker?

  • Docker is a platform for developing, shipping, and running applications using containerization technology.
  • A container is a lightweight, standalone package that contains everything needed to run a piece of software, including the code, runtime, system tools, libraries, and settings.

Why Use Docker?

  • Consistency: Docker containers ensure consistency across multiple development, release cycles, and environments.
  • Speed: Containers are lightweight and fast.
  • Portability: A Docker container can run on any system that supports Docker, eliminating the “it works on my machine” problem.

Basic Concepts

1. Images and Containers

  • An Image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software.
  • A Container is a runtime instance of an image.

2. Docker Hub

  • Docker Hub is a repository for Docker images. You can think of it like GitHub for Docker Images.

3. Dockerfile

  • A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.

Installation

  1. Installing Docker: Visit the Docker website and download the appropriate installer for your operating system.

Your First Docker Container

Step 1: Pull an Image

  • Open a terminal and pull a basic image, like Ubuntu: docker pull ubuntu

Step 2: Run a Container

  • To run a container using this image: docker run -it ubuntu /bin/bash
  • This command creates and starts a container. -it allows you to interact with the container.

Step 3: Experiment Inside the Container

  • Once inside the container, try running commands like ls, pwd, or echo "Hello Docker!"

Step 4: Exit the Container

  • Type exit to leave the container.

Building Your Own Docker Image

1. Creating a Dockerfile

  • Make a directory for your project: mkdir mydockerproject
  • Inside this directory, create a file named Dockerfile.
  • Write a simple Dockerfile:
  FROM ubuntu
  RUN apt-get update
  RUN apt-get install -y python3

2. Building the Image

  • Run docker build -t mypython:latest .
  • -t mypython:latest tags your image.

3. Running Your New Image

  • docker run -it mypython:latest /bin/bash
  • You’ll be in a Python3 environment.

Conclusion

Docker is a powerful tool that can make developing, deploying, and running applications much easier. This lesson covers the basics, but there’s much more to learn and explore in Docker’s world.

Docker is vast and versatile. The more you use it, the more proficient you’ll become.
Happy Dockering! 🐳

Hello, I’m Anuj. I make and teach software.

My website is free of advertisements, affiliate links, tracking or analytics, sponsored posts, and paywalls.
Follow me on LinkedIn, X (twitter) to get timely updates when I post new articles.
My students are the reason this website exists, crafted with the affection and dedication they’ve shown. ❤️

Feedback Display