Skip to content

Practice Exercise 3: Docker Troubleshooting

Objective

The objective of this lab exercise is to familiarize with common Docker troubleshooting scenarios and techniques for diagnosing and resolving Docker-related issues.

Prerequisites

  • Access to your instance with Docker installed.Follow the steps in Lab Environment
  • Basic familiarity with Linux command line.
  • Sudo access

Duration: 60 minutes

Tasks

Task 1. Container Inspection and Logs

Scenario: You have a running Docker container, but you suspect there might be issues. Your task is to inspect the container and view its logs to identify and troubleshoot the problem.

  1. Run a container

        docker run -d --name troubleshoot-container nginx
    
  2. Check container status

        docker ps
    
  3. Inspect Container

        docker inspect troubleshoot-container
    
  4. View container logs

        docker logs troubleshoot-container
    

Task 2. Network Troubleshooting

Scenario: You have containers that need to communicate with each other over a network, but there seems to be an issue. Below are the checks you can run to check any networking issue.

  1. Run Two Containers

        docker run -d --name container1 alpine sleep 3600
        docker run -d --name container2 alpine sleep 3600
    
  2. Check Container IP Addresses

        docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container1
        docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container2
    
  3. Ping Between Containers

        docker exec container1 ping <container2_IP>
    

Note: You can run also telnet to check network issue.

Task 3. Image Pulling Problem

a. Pull a Docker image that does not exist on the server by using a non-existent image name.

b. Analyze the error message.

Task 5. Port Conflict

Scenario: Run a web server container on port 8080 using the following command:

  docker run -d -p 8080:80 nginx –-name nginx-conflict

What did you notice?

  1. It will encounter an error about port conflict and it will not create a running container.

  2. Check if it created a container named nginx-conflict using docker ps -a command.

    Note: It will still create a container but since it encountered a port conflict error, this will not run even after using docker start command.

  3. Try to resolve the conflict using the same name. Note: You will encounter issues with port and container name

Conclusion

After completing these troubleshooting exercises, you should have a better understanding of how to identify and resolve common Docker-related issues on a Linode server. This hands-on experience will help you become more proficient in managing Docker containers in real-world scenarios.