Câu hỏi phỏng vấn Docker
Câu hỏi

Is there a way to identify the status of a Docker container?

Câu trả lời

Yes, there are several ways to identify the status of a Docker container. Here are some of the most common methods:

Using docker ps

The docker ps command is the primary way to list and check the status of Docker containers. By default, it shows only running containers, but you can use various options to get more detailed information:

  • List all containers (including stopped ones):

    docker ps -a

    This command will show all containers, regardless of their state (running, stopped, etc.)[1][4][8].

  • Filter by status:

    docker ps --filter "status=running"
    docker ps --filter "status=exited"

    These commands filter the containers based on their status, such as running or exited[10][11].

Using docker inspect

The docker inspect command provides detailed information about a specific container, including its status. You can use it to get the status of a container by its name or ID:

docker inspect --format='{{.State.Status}}' container_name_or_id

This command will return the status of the specified container, such as "running," "exited," "paused," etc.[1][13][14].

Using docker stats

The docker stats command provides a live data stream of resource usage statistics for running containers. While it primarily focuses on resource usage, it also indicates whether a container is running:

docker stats

This command will show the CPU, memory, network, and disk usage for all running containers[15][17].

Using docker logs

The docker logs command shows the logs of a running container. If the container is not running, this command will not return any logs:

docker logs container_name_or_id

This can help you determine if a container is actively running based on the presence of recent log entries[19].

Using docker exec

You can use the docker exec command to run a command inside a running container. If the container is not running, this command will fail:

docker exec container_name_or_id command

For example, running a simple command like `docke...

junior

junior

Gợi ý câu hỏi phỏng vấn

middle

How will you monitor Docker in production?

expert

How containers works at low level?

senior

What is the difference between Docker RUN, CMD and ENTRYPOINT?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào