Run a disposable container
docker run --rm hello-world- Docker pulls the image if it is not already local.
- A container is created and started from the image.
- --rm removes the stopped container automatically.
Understand the problem containers solve, how containers differ from virtual machines, and where Docker Engine fits in the application lifecycle.
Applications rarely consist of source code alone. They depend on runtimes, libraries, configuration and operating-system behavior. A package that works on one machine can fail elsewhere when those dependencies differ.
A container image packages an application with the filesystem content and metadata needed to run it consistently. Docker gives developers and operators a standard workflow to build that image, start containers from it and distribute the image through registries.
On Linux, containers use kernel isolation mechanisms such as namespaces and cgroups. They share the host kernel rather than booting a separate guest kernel for every workload.
A virtual machine virtualizes hardware and normally boots a complete guest operating system. Containers are typically lighter and faster to start, while virtual machines provide a different isolation boundary and operating-system model.
Docker Engine manages images, containers, networks and volumes. The Docker CLI sends requests to the Engine API. Modern Docker Engine relies on lower-level container runtime components under the hood, but Fundamentals learners should focus first on the user-facing workflow: build, run, inspect, connect, persist and remove.
docker run --rm hello-worlddocker image ls
docker ps
docker ps -aGoal: Create two containers from one image and observe that the image remains while container instances come and go.
docker pull alpine:3.20docker run --name dockerlab-one alpine:3.20 sh -c "echo one > /tmp/value; cat /tmp/value"
docker run --name dockerlab-two alpine:3.20 sh -c "echo two > /tmp/value; cat /tmp/value"docker ps -a --filter name=dockerlab-
docker image ls alpine:3.20docker rm dockerlab-one dockerlab-twoCI/CD systems routinely build one image and create many short-lived containers from that immutable artifact.
Open each answer only after you have tried to answer the question yourself.
An image is the packaged template; a container is a runtime instance created from that image.
They normally run isolated processes while sharing the host kernel instead of booting a full guest operating system.
Storage and distribution of container images.