Back to Blog
An Introductory Guide to the Docker Foundation

An Introductory Guide to the Docker Foundation

March 24, 2025 (1mo ago)

dockerkubernetesdevopscontainersai-tools

Foundation of containers

Container is a lightweight, standalone and executable software package that includes everything necessary to run a piece of software, such as the application code, runtime, system tools, libraries and settings. This encapsulation ensures that the application operates consistently across various computing environments, from development and testing to production

How to work containers


Container vs Virtual Machine (Hypervisor)

​Docker containers and virtual machines (VMs) are both technologies that enable the deployment of applications within isolated environments, but they differ significantly in their architecture and resource utilization.

Docker is much more optimized, up to 100 times faster than VMs and enhances load balancing.


Why Developers should use containers ?

​*Containers offer developers several key benefits :*​


Behind the Scenes: How It Works When You Run Your First Container

​When you execute the

docker run
command, Docker performs several key actions to set up and run your containerized application

  1. Image Retrieval: Docker checks if the specified image is available locally. If not, it pulls the image from a Docker Hub. ​

  2. Container Creation: Using the image, Docker creates a new container. This involves setting up isolated environments using namespaces and control groups to ensure the container operates independently.

  3. File system Setup : Docker mounts a writable layer on top of the image’s read-only file system, allowing the container to modify files during its execution without altering the original image. ​

  4. Network Configuration: Docker assigns the container a unique IP address and sets up networking rules, enabling communication with other containers and external systems as defined.

  5. Application Execution: Finally, Docker runs the specified application or command within this isolated environment, ensuring consistent behavior regardless of the host system's configuration.


Key Docker Concepts : Images, Containers, Docker files

  1. Docker Images : A Docker image is a lightweight, standalone, and executable package that includes everything needed to run a piece of software: code, runtime, libraries, environment variables, and configuration files

  2. Docker Containers : A container is a runtime instance of a Docker image. It is a lightweight, standalone, and executable package that includes everything needed to run a piece of software

  3. Docker Files : A Dockerfile is a script containing a series of instructions that define how to build a Docker image. It automates the creation of containers by specifying the base image, dependencies, configurations and commands needed to run an application.


Basic Docker CLI commands

## 1. Running Containers

```sh
# Run a container from an image
docker run <image>

# Run a container in detached mode (background)
docker run -d <image>

# Run a container with a custom name
docker run --name my-container <image>

# Run a container and map port 8080 on host to 80 in container
docker run -p 8080:80 <image>

# Mount a volume from the current directory to /app in the container
docker run -v $(pwd):/app <image>

# Run a container interactively with a shell
docker run -it <image> sh
```

## 2. Managing Running Containers

```sh
# List running containers
docker ps

# List all containers (including stopped ones)
docker ps -a

# Show logs of a specific container
docker logs <container>

# Attach to a running container's terminal
docker attach <container>

# Stop a running container
docker stop <container>

# Kill a container (force stop)
docker kill <container>

# Stop all running containers
docker stop $(docker ps -q)
```

## 3. Removing Containers

```sh
# Remove a specific container
docker rm <container>

# Force remove a container
docker rm -f <container>

# Remove all stopped containers
docker container prune
```

## 4. Copying Files to and from Containers

```sh
# Copy a file from a container to the host
docker cp <container>:/path/to/file ./
```

Conclusion

In conclusion, Docker is a powerful tool for developers, offering portability, efficiency, and scalability in application deployment.

If you found this blog post helpful, please consider sharing it with others who might benefit. You can also follow me for more content on JavaScript, React.js, Next.js, and other web Development , Devops topics.

For Paid collaboration, Web Development freelancing work, mail me at: krishdesai044@gmail.com

Connect with me on Twitter, LinkedIn, and GitHub.

Thank you for Reading

Happy Coding