Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opening ipv4 listen socket on port 1883 Error: Address already in use #3181

Closed
zjt003 opened this issue Dec 5, 2024 · 5 comments
Closed
Labels
Status: Available No one has claimed responsibility for resolving this issue.

Comments

@zjt003
Copy link

zjt003 commented Dec 5, 2024

docker exec -it be5004c7c0cb sh
/ # mosquitto -v
1733404635: mosquitto version 2.0.20 starting
1733404635: Using default config.
1733404635: Starting in local only mode. Connections will only be possible from clients running on this machine.
1733404635: Create a configuration file which defines a listener to allow remote access.
1733404635: For more details see https://mosquitto.org/documentation/authentication-methods/
1733404635: Opening ipv4 listen socket on port 1883.
1733404635: Error: Address in use
1733404635: Opening ipv6 listen socket on port 1883.
1733404635: Error: Address in use

docker logs be5004c7c0cb
1733404263: mosquitto version 2.0.20 starting
1733404263: Config loaded from /mosquitto/config/mosquitto.conf.
1733404263: Starting in local only mode. Connections will only be possible from clients running on this machine.
1733404263: Create a configuration file which defines a listener to allow remote access.
1733404263: For more details see https://mosquitto.org/documentation/authentication-methods/
1733404263: Opening ipv4 listen socket on port 1883.
1733404263: Opening ipv6 listen socket on port 1883.
1733404263: mosquitto version 2.0.20 running

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Dec 5, 2024
@reubenmiller
Copy link

General advice: It would be more helpful to provide the full details of how you are actually running mosquitto, e.g. what docker run command are you using to start it? Given that this is an open source project, providing as much information as possible would help you get better and quicker answers to your project.

TLDR; This is expected since you're accidentally starting a second mosquitto process inside the container by running mosquitto inside a docker exec -it session.

More detailed answer
Since you haven't provide exactly how you are running mosquitto under docker, I'm assuming you've already executed the docker run, something like below (taken from the docker hub page, and I just removed the volume mount for simplicity).

$ docker run -it -p 1883:1883 eclipse-mosquitto

After a container starts, that will start the mosquitto process. If you then open a new shell inside the container using docker exec -it <container> sh, and then start a second instance of mosquitto, it will fail (as you have shown) because there is already an instance of mosquitto running inside the container. The docker logs are showing the output of the first mosquitto instance, so that is why you don't see an error message there.

@zjt003
Copy link
Author

zjt003 commented Dec 6, 2024

**一般建议 **:提供您实际如何运行 mosquitto 的完整详细信息会更有帮助,例如,您使用什么 docker run 命令来启动它?鉴于这是一个开源项目,提供尽可能多的信息将帮助您更好、更快地获得项目答案。

**顶级域名; ** 这是意料之中的,因为您通过运行 mosquittodocker exec -it 会期。

**更详细的答案 ** 由于您没有提供在 docker 下运行 mosquitto 的确切方法,因此我假设您已经执行了 docker run,如下所示(取自 docker hub 页面,为简单起见,我刚刚删除了卷挂载)。

$ docker run -it -p 1883:1883 eclipse-mosquitto

容器启动后,将启动 mosquitto 进程。如果您随后使用 docker exec -it <container> sh,然后启动第二个 mosquitto 实例,它将失败(如您所展示的),因为容器内已经有一个 mosquitto 实例正在运行。这 docker logs 显示第一个 mosquitto 实例的输出,因此您在此处看不到错误消息的原因。

docker-compose.yml

services:
  mosquitto:
    image: eclipse-mosquitto
    tty: true
    container_name: mosquitto
    ports:
      - '13003:1883'
      - '13004:9001'
    volumes:
      - './config/mosquitto.conf:/mosquitto/config/mosquitto.conf'
      - './data:/mosquitto/data'
      - './log:/mosquitto/log'

Unable to connect through port 13003.
What methods can be used to solve this, or do we absolutely have to use port 1883?

@reubenmiller
Copy link

@zjt003 You need to provide your mosquitto.conf file that you're using.

But guessing, you're missing the following line to create a listener on port 1883 (inside the container):

listener 1883 0.0.0.0

Then afterwards, you can use normal docker port mapping to map the internal container port 1883 to the outside world port, 13003 (but you are already doing this in your docker-compose.yaml file with the line 13003:1883

@reubenmiller
Copy link

You can see all of the mosquitto configuration file documentation here: https://mosquitto.org/man/mosquitto-conf-5.html

@zjt003
Copy link
Author

zjt003 commented Dec 7, 2024

@zjt003 您需要提供您的 mosquitto.conf 文件。

但猜想一下,您错过了以下在端口 1883(容器内)创建侦听器的代码行:

listener 1883 0.0.0.0

然后,你可以使用普通的 docker 端口映射,将内部容器端口 1883 映射到外部世界端口, 13003 (但您已经在 docker-compose.yaml 文件中使用 13003:1883

After adding the configuration, you can connect, thank you

@zjt003 zjt003 closed this as completed Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Available No one has claimed responsibility for resolving this issue.
Projects
None yet
Development

No branches or pull requests

2 participants