Q1. How will you ensure that container 1 runs before container 2 while using docker-compose?
Docker-compose does not wait for any container to be “ready” before going ahead with the next containers.
In order to achieve the order of execution, we can use:
The “depends_on” which got added in version 2 of docker-compose can be used as shown in a sample docker-compose.yml file below:
version: "2.4"
services:
backend:
build: .
depends_on:
- db
db:
image: postgres
The introduction of service dependencies has various causes and effects:
The docker-compose-up command starts and runs the services in the dependency order specified. For the above example, the DB container is started before the backend. docker-compose up SERVICE_NAME by default includes the dependencies associated with the service. In the given an example, running docker-compose up backend creates and starts DB (dependency of backend).
Finally, the command docker-compose stop also stops the services in the order of the dependency specified. For the given example, the backend service is stopped before the DB service.
Q2. Will you lose your data, when a docker container exists?
No, you won’t lose any data when the Docker container exits. Any data that your application writes to the container gets preserved on the disk until you explicitly delete the container. The file system for the container persists even after the container halts.
Q3. Where do you think Docker is being used?
Docker is being used in the following areas:
Simplifying configuration: Docker lets you put your environment and configuration into code and deploy it.
Code Pipeline Management: There are different systems used for development and production. As the code travels from development to testing to production, it goes through a difference in the environment. Docker helps in maintaining the code pipeline consistency.
Developer Productivity: Using Docker for development gives us two things – We’re closer to production and the development environment is built faster.
Application Isolation: As containers are applications wrapped together with all dependencies, your apps are isolated. They can work by themselves on any hardware that supports Docker.
Debugging Capabilities: Docker supports various debugging tools that are not specific to containers but work well with containers.
Multi-tenancy: Docker lets you have multi-tenant applications avoiding redundancy in your codes and deployments.
Rapid Deployment: Docker eliminates the need to boost an entire OS from scratch, reducing the deployment time.
Q4. How is Docker different from other containerization methods?
Docker containers are very easy to deploy in any cloud platform. It can get more applications running on the same hardware when compared to other technologies, it makes it easy for developers to quickly create, ready-to-run containerized applications and it makes managing and deploying applications much easier. You can even share containers with your applications.
If you have some more points to add you can do that but make sure the above explanation is there in your answer.
Q5. Can I use JSON instead of YAML for my compose file in Docker?
You can use JSON instead of YAML for your compose file, to use JSON file with composing, specify the JSON filename to use, for eg:
$ docker-compose -f docker-compose.json up
Q6. Does Docker offer support for IPV6?
Yes, Docker provides support for IPv6. IPv6 networking is supported only on Docker daemons run on Linux hosts. However, if you want to enable IPv6 support in the Docker daemon, you need to modify /etc/docker/daemon.json and set the ipv6 key to true.
Q7. How far do Docker containers scale? Are there any requirements for the same?
Large web deployments like Google and Twitter and platform providers such as Heroku and dotCloud, all run on container technology. Containers can be scaled to hundreds of thousands or even millions of them running in parallel. Talking about requirements, containers require the memory and the OS at all times and a way to use this memory efficiently when scaled.
Q8. What platforms does docker run on?
Docker runs on various Linux administration:
Ubuntu 12.04, 13.04 et al
Fedora 19/20+
RHEL 6.5+
CentOS 6+
Gentoo
ArchLinux
openSUSE 12.3+
CRUX 3.0+
It can also be used in production with Cloud platforms with the following services:
Amazon EC2
Amazon ECS
Google Compute Engine
Microsoft Azure
Rackspace
Q9. Is there a way to identify the status of a Docker container?
There are six possible states a container can be at any given point – Created, Running, Paused, Restarting, Exited, or Dead.
Use the following command to check for docker state at any given point:
$ docker ps
The above command lists down only running containers by default. To look for all containers, use the following command:
$ docker ps -a
Q10. Can you remove a paused container from Docker?
The answer is no. You cannot remove a paused container. The container has to be in the stopped state before it can be removed.
Q11. Can a container restart by itself?
No, it’s not possible for a container to restart by itself. By default the flag -restart is set to false.
Q12. Is it better to directly remove the container using the rm command or stop the container followed by removing the container?
Its always better to stop the container and then remove it using the remove command.
$ docker stop <coontainer_id>
$ docker rm -f <container_id>
Stopping the container and then removing it will allow sending SIG_HUP signal to recipients. This will ensure that all the containers have enough time to clean up their tasks. This method is considered a good practice, avoiding unwanted errors.
Q13. Will cloud overtake the use of Containerization?
Docker containers are gaining popularity but at the same time, Cloud services are giving a good fight. In my personal opinion,
Docker will never be replaced by Cloud. Using cloud services with containerization will definitely hype the game. Organizations need to take their requirements and dependencies into consideration into the picture and decide what’s best for them. Most companies have integrated Docker with the cloud. This way they can make the best out of both technologies.
Q14. How many containers can run per host?
There can be as many containers as you wish per host. Docker does not put any restrictions on it. But you need to consider every container needs storage space, CPU, and memory which the hardware needs to support. You also need to consider the application size. Containers are considered to be lightweight but very dependent on the host OS.
Q15. Is it a good practice to run stateful applications on Docker?
The concept behind stateful applications is that they store their data in the local file system. You need to decide to move the application to another machine, retrieving data becomes painful. I honestly would not prefer running stateful applications on Docker.
Q16. Suppose you have an application that has many dependent services. Will docker-compose wait for the current container to be ready to move to the running of the next service?
The answer is yes. Docker composes always runs in the dependency order. These dependencies are specifications like depends_on, links, volumes_from, etc.
Q17. How will you monitor Docker in production?
Docker provides functionalities like docker stats and docker events to monitor docker in production. Docker stats provides CPU and memory usage of the container. Docker events provide information about the activities taking place in the docker daemon.
Q18. Is it a good practice to run Docker compose in production?
Yes, using docker-compose in production is the best practical application of docker-compose. When you define applications with composing, you can use this compose definition in various production stages like CI, staging, testing, etc.
Q19. What changes are expected in your docker-compose file while moving it to production?
These are the following changes you need to make to your compose file before migrating your application to the production environment:
Remove volume bindings, so the code stays inside the container and cannot be changed from outside the container.
Binding to different ports on the host.
Specify a restart policy
Add extra services like log aggregator
Q20. Are you aware of load balancing across containers and hosts? How does it work?
While using docker service with multiple containers across different hosts, you come across the need to load balance the incoming traffic. Load balancing and HAProxy are basically used to balance the incoming traffic across different available(healthy) containers. If one container crashes, another container should automatically start running and the traffic should be re-routed to this new running container. Load balancing and HAProxy work around this concept.
Q21. How does communication happen between the Docker client and Docker Daemon?
You can communicate between the Docker client and Docker Daemon with the combination of Rest API, socket.IO, and TCP.
Q22. Explain the Implementation method of Continuous Integration(CI) and Continues Development (CD) in Docker?
You need to do the following things:
Runs Jenkins on docker
You can run integration tests in Jenkins using docker-compose
Q23. What is the command to control Docker with Systemd?
systemctl start/stop docker
service docker start/stop
Q24. How can you run multiple containers using a single service?
By using docker-compose, you can run multiple containers using a single service. All docker-compose files use yaml language.
Q25. What is CNM?
CNM stands for Container Networking Model. It is a standard or specification from Docker, Inc. that forms the basis of container networking in a Docker environment. This docker approach provides container networking with support for multiple network drivers.
Exception Handling Interview Questions
DBMS Interview Questions Set -1
DBMS Interview Questions Set -2
JPA Interview Questions Set -1
Spring Boot Interview Questions Set 1
Spring Boot Interview Questions Set 2
Core Java Interview Questions Set -1
Docker interview question Set -1
Docker interview question Set -2
No comments:
Post a Comment