Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Installation and Basics Running First Container docker run helloworld
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-installation-and-basics-running-first-container-docker-run-helloworld

Docker Docker Installation and Basics Running First Container docker run helloworld

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

1. Core Command / Concept

Run a container from an existing Docker image. docker run.

2. Step-by-Step

  1. Check if Docker is installed and running: docker --version
  2. Pull the official "hello-world" image: docker pull hello-world
  3. Run the container from the pulled image: docker run hello-world
    ⚠️ Output should be a short message indicating the container ran successfully.
  4. List all running containers: docker ps
  5. Stop the container: docker stop <container_id>
  6. Remove the container: docker rm <container_id>
    ⚠️ This deletes all stopped containers: docker system prune -f

3. Real Commands with Examples


Example 1: Run a container with a specific name

Purpose: Run a container with a custom name.
Command: docker run --name myhello hello-world Brief explanation of flags: --name sets the container name.

Example 2: Run a container with a specific port mapping

Purpose: Run a container and map port 80 to host port 8080.
Command: docker run -p 8080:80 hello-world Brief explanation of flags: -p maps a host port to a container port.

Example 3: Run a container with a specific environment variable

Purpose: Run a container with an environment variable set.
Command: docker run -e MY_VAR=hello hello-world Brief explanation of flags: -e sets an environment variable.

4. Common Errors


Error 1: Image not found

Error message or symptom: docker: Error response from daemon: No such image: hello-world.
Why it happens: The image was not pulled or does not exist.
One-line fix: docker pull hello-world.

Error 2: Container not found

Error message or symptom: docker: Error response from daemon: No such container: <container_id>.
Why it happens: The container was not created or does not exist.
One-line fix: docker run hello-world.

Error 3: Port mapping conflict

Error message or symptom: docker: Error response from daemon: Conflict: you tried to bind to port 80 which is already bound by container <container_id>.
Why it happens: A container is already using the specified port.
One-line fix: docker stop <container_id> and then docker rm <container_id>.

5. Quick Checks


Scenario 1: Container is running

Situation: You want to check if a container is running.
Command to run: docker ps What a correct response looks like: A list of running containers.

Scenario 2: Container is stopped

Situation: You want to check if a container is stopped.
Command to run: docker ps -a What a correct response looks like: A list of all containers, including stopped ones.

Scenario 3: Image is pulled

Situation: You want to check if an image is pulled.
Command to run: docker images What a correct response looks like: A list of available images.

6. Last-Minute Reference

docker run command flags: -d, -i, -t, -p, -e, --name • Default container name: docker-<container_id> • Default port mapping: host_port:container_port • Docker image names: docker.io/<username>/<image_name> • Docker image tags: <image_name>:<tag> • Docker container IDs: docker ps -q • Docker image IDs: docker images -q • Docker version: docker --version • Docker system prune: docker system prune -f • Docker container stop: docker stop <container_id> • Docker container remove: docker rm <container_id> • Docker image pull: docker pull <image_name> • Docker image push: docker push <image_name>




ADVERTISEMENT