Ionic app serving from Linux container

Running Docker3.5.2 on Windows 10 21H1. DockerFile:

FROM beevelop/ionic:latest
WORKDIR /www/app
COPY . /www/app
EXPOSE 8100
ENTRYPOINT ["ionic"]
CMD ["serve", "--external", "--no-open"]

Running the image produced, I can see that it does the Ionic serve correctly, offers me to connect to http://172.17.0.2:8100 - I cannot connect. Networking seems fine. If I connect into the running image - had to install ping, ip, etc on the image - the bridging is working fine. I can ping IP addresses on my machine, ping out to the web from within the Docker image.

To test whether networking into a Docker container from my machine, I ran the nginx web server app image 8000:80, and can connect in to that just fine.

I cannot disable my local firewall as the machine is a member of the University’s domain, where I work, but I added rules for port 8100, no change. Tried serving on a different port, same deal.

I am getting a bit weary from bashing my head against this brick wall :slight_smile: Any help would be greatly appreciated.

John Jensen, Application Specialist
University of Auckland

How are you running the image? Are you publishing port 8100, using -p 8100:8100? If yes, did you also try localhost / 127.0.0.1 instead of 172.17.0.2?

Were you also using something like 172.17.0.2 in that test, or just localhost / 127.0.0.1?

1 Like

This appears to be a context issue: you try to use connection details ment for the container on your host.
In almost every case, using the container ip is not what you want or should do. Instead use the published host port or for container-to-container communication the container or service name (this requires a user defined network, as dns-based service discovery is not available for the default bridge).

From the host, you should be able to accessible the Ionic app from http://localhost:8100

Yes – that’s what I assumed, but it doesn’t work – neither, of course, does the one for the IP inside the container.

jj

So, how are you running the image?

Yes - actually, I tried various combinations of port mappings. I did try localhost but didn’t try 127.0.0.1. I will.

Tried various port mappings – starting, of course, from 8100:8100

In case it helps, the following works for me on a Mac (with Linux containers) using http://localhost:8100 and http://127.0.0.1:8100, testing with your Dockerfile:

npm i -g @ionic/cli 
ionic start my-ionic-app tabs --type=angular --capacitor
cd my-ionic-app

# Copying your text into Dockerfile:
vi Dockerfile

docker build -t my-ionic-app .
docker run --rm -p 8100:8100 my-ionic-app
> ng run app:serve --host=0.0.0.0 --port=8100
[ng] Warning: This is a simple server for use in testing or debugging Angular applications
[ng] locally. It hasn't been reviewed for security issues.
...
[ng] ✔ Compiled successfully.

[INFO] Development server running!
       
       Local: http://localhost:8100
       External: http://172.17.0.2:8100
       
       Use Ctrl+C to quit this process
...

(Ionic or Angular CLI clearly does not know it’s running in a Docker container.)

Thank you – and thank all of you who have replied. It now works. The only difference I know of is that I finally tried something I should have done before: rebooted.

I should have done that ages ago. When I have had to do tech support, one of the things I suggest very early is: reboot!

1 Like