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.
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.
To create and run a container from an image, you can use the following Docker CLI commands:
bash
docker pull python:3.8-slim
docker run -d -p 4000:80 python:3.8-slim
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.
Dockerfile FROM ubuntu:20.04
RUN apt-get update && apt-get install -y
build-essential
python3
python3-pip
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.
- Create an Account: Sign up at Docker Hub.
- Push an Image:
bash docker login docker tag my-image myusername/my-image:latest docker push myusername/my-image:latest
- Pull an Image:
bash docker pull myusername/my-image:latest
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.