- Images: Read-only templates used to create containers. They contain the application code, libraries, dependencies, and configurations.
- Containers: Runnable instances of an image. They are isolated, lightweight environments where your application runs.
- Docker Daemon: The background service that manages Docker objects.
- Docker Client: The command-line tool (or other clients) that interacts with the Docker Daemon.
- Docker Hub: A public registry for Docker images.
-
Install Docker: Follow the official Docker documentation for your operating system (Docker Desktop for Windows/macOS, or Docker Engine for Linux).
-
Verify Installation:
docker --version
docker run hello-world(The hello-world command pulls a tiny image and runs a container from it, printing a message.)
3. Pull an image:
docker pull ubuntu:latest- Run a container from an image (non-interactive):
docker run ubuntu:latest echo "Hello from Ubuntu container! "- Run an interactive container:
docker run -it --name my_ubuntu_shell ubuntu:latest /bin/bash(This runs an Ubuntu container in interactive (-i) and pseudo-TTY (-t) mode, names it my_ubuntu_shell, and opens a bash shell inside it. Type exit to leave the container.)
- List running containers:
docker ps- List all containers (running and stopped):
docker ps -a- Stop a running container:
docker stop my_ubuntu_shell- Restart a stopped container:
docker start my_ubuntu_shell
docker attach my_ubuntu_shell # Re-attach to the bash session- Remove a container:
docker rm my_ubuntu_shell- List images:
docker images- Remove an image:
docker rmi ubuntu:latest- Run a
debian:latestcontainer in interactive mode and try to install a package likecurlinside it. What happens and why? (Hint: Think about what's included in a minimal Debian image.) - After exiting, try to start and re-attach to the same container.
- Clean up by removing the container.