Docker Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is Docker?
Docker is a containerization platform that allows developers to package, distribute, and run applications in isolated environments called containers.
Example:
docker run -d -p 80:80 nginx
Ques 2. What is the purpose of Dockerfile?
Dockerfile is a script that contains instructions for building a Docker image. It specifies the base image, application code, dependencies, and other configurations.
Example:
FROM ubuntu
RUN apt-get update && apt-get install -y nginx
Ques 3. What is the difference between a Docker image and a Docker container?
An image is a lightweight, standalone, and executable package that includes everything needed to run a piece of software. A container is a runtime instance of a Docker image.
Example:
docker run -d my_image
Ques 4. How do you remove all Docker containers?
You can use the following command to remove all Docker containers: docker rm $(docker ps -a -q)
Example:
docker rm $(docker ps -a -q)
Ques 5. How do you check the logs of a running Docker container?
You can use the `docker logs` command followed by the container ID or name to view the logs of a running container.
Example:
docker logs container_name
Ques 6. What is the purpose of Docker Hub?
Docker Hub is a cloud-based registry service that allows developers to share and distribute Docker images. It serves as a central repository for Docker images.
Ques 7. How do you remove a Docker image?
You can use the `docker rmi` command followed by the image ID or name to remove a Docker image.
Example:
docker rmi image_name
Ques 8. How do you pass environment variables to a Docker container?
Environment variables can be passed to a Docker container using the `-e` or `--env` option with the `docker run` command.
Example:
docker run -e MY_VARIABLE=value my_image
Ques 9. What is Docker Registry?
Docker Registry is a storage and distribution system for Docker images. It can be a public registry like Docker Hub or a private registry hosted within an organization.
Ques 10. How do you build a Docker image from a Dockerfile?
You can use the `docker build` command followed by the path to the directory containing the Dockerfile.
Example:
docker build -t my_image:latest .
Most helpful rated by users: