How to access a WebAPI service running on a Colibri iMX6DL

Hi there,

Hardware:
Colibri iMX6DL
with Viola Carrier Board Rev 1.2
Torizon OS 6.4.0

image

We are setting up a Web API in C# i.e.

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet(“/”, () => “Hello World!”);

app.Urls.Add(“http://*:5003”); // :point_left: Add the URL
app.Run();

When we try and access the WebAPI from a PC (on the same network) we get a “Refused to connect” error.

Do we need to map the port “5003” or include something in the Docker file to allow access to the Colibri IP address + Port Number.

Many Thanks
Jon

Hi, I’m the Toradex AI Assistant. The Toradex Support team will follow up with you shortly!

Did you like my answer?

:+1: :-1:


Hi Jon,

To access a Web API service running on your Colibri iMX6DL with Torizon OS, you need to ensure that the Docker container running your Web API is properly configured to expose the necessary port. Here are the steps you can follow:

  1. Expose the Port in the Dockerfile:
    Ensure that your Dockerfile includes the EXPOSE instruction for the port your Web API is using. For example:

    EXPOSE 5003
    
  2. Run the Docker Container with Port Mapping:
    When you run your Docker container, you need to map the container port to a port on the host (your Colibri module). You can do this using the -p option with docker run. For example:

    docker run -d -p 5003:5003 your-docker-image
    

    This command maps port 5003 on the host to port 5003 in the container.

  3. Check Network Configuration:
    Ensure that your Colibri module and the PC are on the same network and that there are no firewall rules blocking the connection. You can test the network connectivity using ping or telnet from the PC to the Colibri module’s IP address.

  4. Verify the Web API is Running:
    Make sure that your Web API service is running correctly inside the container. You can check the logs of the container to see if there are any errors:

    docker logs <container_id>
    
  5. Access the Web API:
    From your PC, you should be able to access the Web API using the Colibri module’s IP address and the mapped port. For example:

    http://<colibri_ip_address>:5003
    

If you have followed these steps and are still encountering issues, please provide more details about any error messages or logs, and we can further troubleshoot the problem.

Many Thanks,
[Your Name]

Please, also check if these links can help you solve your problem:

Colibri IMX6 image load issues.

Hi @jon2023

@ToradexAI is correct.

By default the container runs in an isolated environment.
The -p tag is used to map the 5003 port from inside the container to the outside network.

docker run -d -p 5003:5003 your-docker-image

You can check the docker documentation for a full list of options.