Docker EXEC Operations - Level 2 - Task failed with error - - 'apache2' is not configured to use correct port

Hi Team,
Hope you are doing great !

Kindly guide me where I am going wrong :-

  1. In understanding the question regarding the ports or issue.
    – example :- port should be 80:5002 and I am giving 5002:5002
  2. Or I am missing some steps which is being checked by the python script and result is failed task with error given below.

Question Screenshot :-

Things I have tried to verify from my side.

  • First stopped and removed old container then :-
    Created a new container with port number 5002:5002 as per the task given with same

    • name = kkloud,
    • image ubuntu 18:04,
    • installed apache2 inside the container using apt command.
    • changed apache default port 80 to 5002 by updating the file inside container
      file name :- /etc/apache2/ports.conf
  • Check and Verification done from my side

    • Checked docker ps output container is running & it showed mapping of ports like this 5002:5002.

    • Checked from inside the container -

      • correct port number is showing in the file /etc/apache2/ports.conf
      • Apache services are running , even restarted it once and again verified it was running.
      • did the curl on localhost port 5002 (from inside the container) and its working.
      • Installed netstat and verified port 5002 is listing.
    • From the Host CLI verified using -

      • curl on port 5002 - it was working got the output.
      • Installed netstat and verified port 5002 is listing.
    • Since this task failed , I tried once again but got similar error for port 6400 for “Apache server 2”

---------> Relevant Screenshot and Error message I have shared below <----------


**Error :- **
====

  • ‘apache2’ is not configured to use correct port i.e ‘5002’ in ‘kkloud’ container on App Server 3
    FAILED docker-exec.py::test_docker_exec - AssertionError: - ‘apache2’ is not …

Screenshot for curl from host (App Server 3) is working fine for the url : - http://localhost:5002/

Even i have checked for listing port from host and inside the container and its fine.
Screenshot for netstat command output from Host (App Server 3)


**

Since 1st Attempt it failed so I tried 2nd time still getting similar error

**

**Error :- **
====

  • ‘apache2’ is not configured to use correct port i.e ‘6400’ in ‘kkloud’ container on App Server 2
    FAILED docker-exec.py::test_docker_exec - AssertionError: - ‘apache2’ is not …
    Error Screenshot Below

Screenshot for kkloud container file output :-etc/apache2/ports.conf

Screenshot for curl from host (App Server 2) is working fine for the url : - http://localhost:6400/

Hi have faced the same issue with this question.

Hi @Arunabh & @anusharma0426,
Thanks for highlighting this. We will check and get back to you.

If possible, please DM the exact steps you performed in the lab.

Regards,

Hi @Arunabh,
I checked this task and didn’t find any issues. We don’t need to kill and recreate the container.
We need to configure the Apache server this way; it should show the index page on localhost:<PORT>.

Also, I don’t see any line where it says to expose the container port on the host port.

Regards,

Hi @Tej-Singh-Rana , thanks for your reply.
General info/steps I have shared with you in my previous post.

I have tried multiple ways , but to keep it simple you can go with below first and let me know if any doubt or confusion in my steps.

STEPS :-

1) List the container using “docker ps -a”

  • Stop and Remove the container using docker stop , docker rm

2) Create a shell script (start_apache.sh) on Host current directory- with below content

#!/bin/bash

Update package lists and install Apache

apt-get update
apt-get install -y apache2

Change Apache’s default port from 80 to 5002

sed -i ‘s/Listen 80/Listen 5002/’ /etc/apache2/ports.conf

Redirect Apache’s error log to standard output (useful for troubleshooting)

ln -sf /dev/stdout /var/log/apache2/error.log

Start Apache in the foreground

apache2ctl -D FOREGROUND


3) Give executable permission :- chmod +x start_apache.sh

4) Create a container using the below command :-
docker run -d -p 5002:5002 --name kkloud -v “$(pwd)/start_apache.sh:/start_apache.sh” ubuntu:18.04 /bin/bash -c “/start_apache.sh”

5) Verify container is running using docker ps ,check its output for ports or use this command
example :-
docker port kkloud
5002/tcp → 0.0.0.0:5002
5002/tcp → :::5002

6) do curl and test
example :-
$ curl http://localhost:5002/

------------------------------------------------------------------------------------------------------------- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Exact steps I have tried in my AWS VM and its working fine see the screenshot

since Kodekloud Lab is using private Ip , so we can’t see it in browser
But in My AWS i can see the index.html on port 5002 as i have public IP address.

AWS VM :- able to access apache2 on port 5002 and below is screenshot for webpage

We can user w3m or lynx etc… which ever you want to use to check webpage from linux terminal in lab also.

I have shared screenshot from AWS VM cli for apache2 webpage on port 5002
$ w3m http://localhost:5002/

Hi @Arunabh,
Please read my previous comment.

Regards,

@Tej-Singh-Rana
thanks for the update.

I got your point , as per the task no need to expose the port to HOST , we have to curl from container inside , thanks for making it clear.

I have following question/doubts . Kindly guide me on that.

  1. What that python script is checking , can you please tell ?
    – since I want to know why my task failed , if you see I have done extra only that is exposing the port to HOST so that container apache can be accessed outside container also.
    – if script is only checking for apache2 status and contain status inside which it is running then script should have passed and might have not checked for the HOST port.

– is script checking on the container id also – may be this might be leading to failure .

So instead of guessing I want to know why it failed requesting you to kindly share if possible what condition that python script is checking.


Since you mentioned , I checked that lab again just to check but today :-
– i found that Ubuntu container was running and was showing on docker ps command output ,
– Yesterday I was not able to see the container under "docker ps " i was only able to see it under “docker ps -a” , that’s why I was creating a new container.