Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

How will you ensure that a container 1 runs before container 2 while using docker compose?

Answer»

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 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.
2.

How to use docker for multiple application environments?

Answer»
  • Docker-compose feature of docker will come to help here. In the docker-compose file, we can define multiple services, networks, and containers along with the volume mapping in a clean manner, and then we can just call the command “docker-compose up”.
  • When there are multiple environments involved - it can be EITHER DEV, staging, uat, or production SERVERS, we would want to define the server-specific dependencies and processes for running the application. In this case, we can go ahead with creating environment-specific docker-compose files of the name “docker-compose.{environment}.yml” and then based on the environment, we can SET up and run the application.
3.

Describe the lifecycle of Docker Container?

Answer»

The different stages of the docker container from the START of creating it to its end are CALLED the docker container life cycle. 
The most important stages are:

  • CREATED: This is the state where the container has just been created NEW but not started yet.
  • Running: In this state, the container would be running with all its associated processes.
  • Paused: This state happens when the running container has been paused.
  • Stopped: This state happens when the running container has been stopped.
  • Deleted: In this, the container is in a DEAD state.
4.

How many containers you can run in docker and what are the factors influencing this limit?

Answer»

There is no clearly defined limit to the number of containers that can be RUN within docker. But it all DEPENDS on the limitations - more specifically hardware restrictions. The size of the app and the CPU resources available are 2 important factors influencing this limit. In CASE your application is not very BIG and you have ABUNDANT CPU resources, then we can run a huge number of containers.

5.

Can we use JSON instead of YAML while developing docker-compose file in Docker?

Answer»

YES! It can be USED. In order to run docker-compose with JSON, docker-compose -f docker-compose.json up can be used.