admin管理员组文章数量:1193969
I am running a Node.js application inside a Docker container, and I'm using Axios to make HTTP requests to an external API. The same request works fine when running the app on my local machine, but when I try to make the request from inside the Docker container, I get the following error:
AxiosError: Request failed with status code ENOTFOUND
Here's the Axios code I’m using:
const axios = require('axios');
const fetchData = async () => {
try {
const response = await axios.get('');
console.log(response.data);
} catch (error) {
console.error('Error: ', error.message);
}
};
fetchData();
The container is able to access the internet for other operations like pulling Docker images, but when trying to connect to the external API, it fails with the ENOTFOUND
error.
I tried using
--network host
to run the container on the host machine's network, but the error still occurs.I expected the request to be able to connect to the external API from inside the Docker container, just as it does on my local machine.
本文标签:
版权声明:本文标题:node.js - How can I fix ENOTFOUND error when accessing an external API using Axios inside a Docker container? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738493364a2089837.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论