By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Docker provides reproducibility, portability, isolation, and efficiency by packaging applications and their dependencies into containers. docker run
docker run
sudo apt-get update && sudo apt-get install docker.io
docker --version
sudo systemctl status docker
touch Dockerfile
docker build -t myimage .
docker run -it myimage
docker container prune
docker ps
docker stop <container_id>
Purpose: Run a web server using the official Python image.Command: docker run -p 8080:80 python:3.9-slim Flags: -p maps port 8080 on the host to port 80 in the container, python:3.9-slim is the image name.
docker run -p 8080:80 python:3.9-slim
-p
python:3.9-slim
Purpose: Run a PostgreSQL database server.Command: docker run -d -p 5432:5432 --name mydb postgres:13 Flags: -d runs the container in detached mode, -p maps port 5432 on the host to port 5432 in the container, --name sets the container name, postgres:13 is the image name.
docker run -d -p 5432:5432 --name mydb postgres:13
-d
--name
postgres:13
Purpose: Run the ls command in a container.Command: docker run -it --rm alpine ls -l Flags: -it runs the container in interactive mode, --rm removes the container after it exits, alpine is the image name.
ls
docker run -it --rm alpine ls -l
-it
--rm
alpine
Error message: docker: Error response from daemon: No such image: myimage.Why it happens: The image does not exist locally or on the Docker registry.Fix: docker pull myimage.
docker: Error response from daemon: No such image: myimage
docker pull myimage
Error message: docker: Error response from daemon: No such container: mycontainer.Why it happens: The container does not exist.Fix: docker ps -a to list all containers.
docker: Error response from daemon: No such container: mycontainer
docker ps -a
Error message: docker: Error response from daemon: Port is already allocated.Why it happens: The port is already in use by another container or process.Fix: docker ps -a to list all containers and find the one using the port, then docker stop and docker rm to stop and remove the container.
docker: Error response from daemon: Port is already allocated
docker stop
docker rm
Situation: You want to check if Docker is installed on your system.Command: docker --version Correct response: The Docker version number.
Situation: You want to check if a container is running.Command: docker ps Correct response: The container ID and name.
Situation: You want to check if an image exists locally.Command: docker images Correct response: The image ID and name.
docker images
docker build
-t
.
-a
-q
<container_id>
docker pull
<image_name>
docker push
docker tag
<image_id>
docker rmi
docker system prune
docker image prune
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.