Docker Community Forums

Share and learn in the Docker community.

How to access the service created via docker

Here is my yaml file. Once I do docker-compose up, I get messages that listen sockets have been opened on these ports. However, if I try to access them by typing “localhost” or “localhost:1883” into the web browser, I dont get back anything. How do I access the service?
If I do curl http://localhost:1883, It just says no response from server. What am I doing wrong here?

version: '3.5'
services:
  mosquitto:
    container_name: mosquitto_container1
    image: eclipse-mosquitto:latest
    restart: always
    volumes:
      - "./config:/mosquitto/config/:rw"
    ports:
      - '1883:1883'
      - '9001:9001'
      - '8883:8883'
      - '8083:8083'
    tty: true  
    networks:
      - default

Here is my conf file

allow_anonymous true
listener 1883
listener 9001
protocol websockets
listener 8883
cafile /mosquitto/config/certs/ca.crt
certfile /mosquitto/config/certs/broker.crt
keyfile /mosquitto/config/certs/broker.key

listener 8083
protocol websockets
cafile /mosquitto/config/certs/ca.crt
certfile /mosquitto/config/certs/broker.crt
keyfile /mosquitto/config/certs/broker.key

require_certificate false

persistence true
persistence_location /mosquitto/data/

tls_version tlsv1.2

Good morning,

mosquitto’s port 1883 is not usable for http - the protocol in use is mqtt.
So to test your service you can use mosquitto_sub and mosquitto_pub.
On Linux they are located in the package mosquitto-clients (at least for Ubuntu and Raspbian where it can be installed with sudo apt-get install mosquitto-clients).

Thank you for responding Matthiasradde. I do see that I can send messages via the mosqitto_sub and mosquitto_pub commands. So, I guess It does make sense that I am not able to access it via http