Adding/editing entry in /etc/hosts file inside azure container app.

Chandrashekar, Anil (Cognizant) 40 Reputation points
2025-04-01T19:17:54.1133333+00:00

Hi

I would like add some ip & corresponding hostname entries to /etc/hosts file within my azure container app. While i was able to do it using 'Debug console', these entries are vanished when container is redeployed and i will have to add these entries again which is cumbersome.

Is there any permanent solution(Dockerfile or any other configurable approach) to this problem where in /etc/hosts entries are not vanished when container are redeployed?

Thanks in advance.

Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
622 questions
{count} votes

Accepted answer
  1. Marcin Policht 44,360 Reputation points MVP
    2025-04-08T03:30:50.63+00:00

    This just means that the file utility isn't installed. You can ignore it, this was just a debug helper.

    Try the following

    FROM openjdk:17
    # Copy startup script
    COPY startup.sh /usr/local/bin/startup.sh
    # Make it executable
    RUN chmod +x /usr/local/bin/startup.sh
    # Set entrypoint and default command
    ENTRYPOINT ["/usr/local/bin/startup.sh"]
    CMD ["java", "-jar", "abc.jar"]
    
    

    where startup.sh contains something like the following:

    #!/bin/sh
    echo "192.168.1.100 mycustomhost" >> /etc/hosts
    exec "$@"
    

    If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.

    hth

    Marcin

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Shireesha Eeraboina 2,815 Reputation points Microsoft External Staff
    2025-04-11T05:50:47.52+00:00

    Hi Chandrashekar, Anil (Cognizant),

    Thanks for all the detailed updates!

    Hi, the issue you're seeing is likely due to your startup.sh script having Windows-style line endings (CRLF), which Linux containers can't read.

    Please change the line endings to Unix (LF) — in VS Code, just click on "CRLF" at the bottom right and select "LF", or use dos2unix startup.sh.

    Also, make sure the script is in the same folder as your Dockerfile and starts with #!/bin/sh. In your Dockerfile, use only one ENTRYPOINT, like this: ENTRYPOINT ["/usr/local/bin/startup.sh"], and define your app command with CMD. This should fix the "no such file or directory" error and allow the hosts entry to be added properly.

    For your reference, please review the following documentations for further clarification:

    https://stackoverflow.com/questions/29535015/error-cannot-start-container-stat-bin-sh-no-such-file-or-directory

    https://forums.docker.com/t/standard-init-linux-go-exec-user-process-caused-no-such-file-or-directory/35691

    I hope this addresses your query. Please let me know if you need any further assistance or clarification.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.