1 year ago

#388755

test-img

Bajo jajo

How to expose port of Docker container for localhost

I have dockerized simple node.js REST API. I'm building container with this API on my raspberry. This node.js app needs to be installed on few raspberry devices, on every device user will be using angular app which is hosted on my server and this client app will send request to this API.

I can connect to api by using IP of container which can be obtained from container VM by using ifconfig - http://{containerIp}:2710.The problem is that my angular app is using HTTPS and API is using HTTP so there will be Mixed content error. That way may also generate additional problem with container IP because every machine can have different container IP but there is one client app with one config.

I suppose if I will configure access to this API for http://localhost:2710 there will be no error, but I don't know how can I make this container visible on raspberry localhost

This is how i'm building my docker environment

Dockerfile

FROM arm32v7/node

RUN mkdir -p /usr/src/app/back
WORKDIR /usr/src/app/back

COPY package.json /usr/src/app/back/

RUN npm install

COPY . /usr/src/app/back/

EXPOSE 2710

CMD [ "node", "index.js" ]

Compose

services:
  backend:
    image: // path to my repo with image
    ports:
      - 2710:2710
    container_name: backend
    privileged: true
    restart: always

node.js

docker

networking

raspberry-pi

localhost

0 Answers

Your Answer

Accepted video resources