Table of Contents
Getting Ready for Your First Container
Before you run your first Docker container, you need Docker installed and working on your machine. The details of installation are covered in a later section, so here you only need to know one thing. A container is a running instance of an image. To start your first container you will use the docker command in a terminal or command prompt, and Docker will take care of downloading the necessary image if it is not already present.
At this point you should be comfortable opening a shell on your system and typing basic commands. You do not need any programming experience yet. The commands you will run are short and you can copy and paste them if needed.
Always run Docker commands in a terminal or command prompt, not inside a programming language shell like Python or Node.js.
Choosing a Simple Starter Image
For your very first container you want an image that is small, predictable, and safe. A popular choice is the hello-world image. Its only purpose is to start briefly, print a clear message that confirms your Docker setup works, and then exit. It does not open network ports or modify files on your system.
Another common starter image is nginx or httpd which runs a simple web server. Those are useful when you want to see a long running container. For now, the focus is on understanding the basic lifecycle of a container from start to stop.
When you use an image name in a Docker command, Docker looks for it locally first. If it does not exist on your machine, Docker automatically attempts to pull it from the default registry, which is usually Docker Hub. This means you can run your first container with a single command without any preparation.
The First Run Experience
Your first container will show the full workflow in one step. You type a command, Docker connects to a registry if needed, downloads the image layers, creates a container from the image, runs the container process, and then prints the output.
With the hello-world example, you should expect several lines of information. You will see messages about pulling the image and then a final explanation that Docker was able to reach the registry, download the image, and run it successfully. The container will exit immediately after printing its message.
Even though the container stops almost instantly, Docker still records that it existed. You can later list stopped containers and see this first run in the history of your Docker usage. This will become important when you start learning how to stop, remove, and inspect containers.
If your first container does not run and you see errors about permissions or the Docker daemon, do not keep retrying the same command. Fix the installation or service issue first before continuing.
Understanding What Just Happened
When your first container runs successfully, several important concepts are already in play, even if you did not notice them yet.
An image served as the template for the container. From that image Docker created an isolated environment with its own filesystem view, process space, and basic configuration. Then Docker started the main process that the image defined. When that process completed, the container stopped. If the process is long running, the container stays up until you stop it.
Even at this early stage, it is important to realize that containers are usually designed around a single main process. The image specifies what that process is, and the container runtime manages it. You will learn later how docker run influences this process and how you can override defaults.
Building Confidence with Repeating the Run
To become comfortable, run the same container command more than once. Each time, Docker checks whether the image is already present. Once it is downloaded, future runs start much faster since they do not need to pull anything from the network.
Repeated runs also help you see that containers are cheap to create and destroy. You are not installing a full application on your host each time. Instead, Docker is reusing the same image and creating new, lightweight containers from it.
You can also experiment with different images by swapping the image name in the command. Try an image that prints something different or one that runs for longer. Even without fully understanding the options, you will start to recognize that the pattern is always the same. You provide an image name, Docker runs a container from it, and you observe what happens.
Preparing for Deeper Commands
After you have successfully started and observed your first container, you are ready for a more detailed look at the command that made it happen. In the next chapters you will break down docker run, learn about interactive and detached modes, see how to stop and remove containers, and list both running and exited ones.
For now, the key achievement is that you have seen Docker in action on your own machine. You have validated that the engine works, that Docker can pull images from a registry, and that you can start containers. Everything that follows will build on this simple but important first step.