Skip to content

Latest commit

 

History

History
77 lines (45 loc) · 2.39 KB

3.essentials.md

File metadata and controls

77 lines (45 loc) · 2.39 KB

Docker Images

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

  • Immutable: Once an image is created, it does not change.
  • Layered: Images are made up of layers. Each layer represents an instruction in the image’s Dockerfile.

Example Dockerfile (DockerFile)

Docker Containers

A Docker 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.

  • Isolation: Containers run in isolated environments.
  • Consistency: Containers ensure consistency across multiple environments.

Managing Containers

To create and run a container from an image, you can use the following Docker CLI commands:

bash

Pull an image from Docker Hub

docker pull python:3.8-slim

Run a container

docker run -d -p 4000:80 python:3.8-slim

Parent Images

Parent images are foundational images used to build other images. They provide a starting point with a basic set of functionalities.

  • Base Layer: The base layer for more complex images.
  • Customization: You can extend parent images to add custom configurations and software.

Example of a Parent Image

Dockerfile FROM ubuntu:20.04

Install dependencies

RUN apt-get update && apt-get install -y
build-essential
python3
python3-pip

Docker Hub

Docker Hub is a cloud-based registry service that allows you to share your Docker images with others. It hosts a central repository of Docker images.

  • Public Repositories: Open to everyone.
  • Private Repositories: For private projects and teams.

Using Docker Hub

  1. Create an Account: Sign up at Docker Hub.
  2. Push an Image:

bash docker login docker tag my-image myusername/my-image:latest docker push myusername/my-image:latest

  1. Pull an Image:

bash docker pull myusername/my-image:latest

Conclusion

Understanding Docker images, containers, parent images, and Docker Hub is essential for modern application development and deployment. Docker simplifies the process of packaging, distributing, and running applications, ensuring consistency across different environments.

For more details, refer to the Docker Documentation.