gpt4 book ai didi

node.js - 映射Docker端口失败

转载 作者:行者123 更新时间:2023-12-02 20:21:56 24 4
gpt4 key购买 nike

使用下面的dockerfile用centos7创建了新的docker image(rm / node:10.0)。

FROM rm/node:9.0
EXPOSE 3000

WORKDIR /Reader_Manager/SISPlatform/Auth
RUN npm install

WORKDIR /Reader_Manager/SISPlatform/Auth/portal
CMD npm run-script dev-server-linux

“npm run-script dev-server-linux”将调用以下在package.json文件中定义的命令
"dev-server-linux": "export NODE_ENV=development && pm2 start --no-daemon AuthServer -o ../../logs/pm2/out/auth_out.log -e ../../logs/pm2/err/auth_error.log --log-date-format 'DD-MM-YYYY HH:mm:ss.SSS'",

当我尝试在后台运行创建的docker镜像时,它正在运行。
docker run -d rm/node:10.0
08633576828fe33ba880c7b6a40dd9306c885d24ce36a765a459f5acc8e91808
Usage of loopback devices is strongly discouraged for production use. Either use `--storage-opt dm.thinpooldev` or use `--storage-opt dm.no_warn_on_loop_devices=true` to suppress this warning.


docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
08633576828f rm/node:10.0 "/bin/sh -c 'npm run-" About a minute ago Up About a minute 3000/tcp nostalgic_gates

当我在容器内运行nodejs时,暴露了3000端口。因此,我尝试映射3000端口,但失败并显示错误。
[dkanagaraj@localhost docker_test]$ docker run -p 3000:3000 -d rm/node:10.0
3160c27cd2ee964474d137024c1f392dafe5242874842b5f5cdf28a4dfb27e51
Error response from daemon: Cannot start container 3160c27cd2ee964474d137024c1f392dafe5242874842b5f5cdf28a4dfb27e51: failed to create endpoint big_wing on network bridge: COMMAND_FAILED: '/sbin/iptables -w2 -t nat -A DOCKER -p tcp -d 0/0 --dport 3000 -j DNAT --to-destination 172.17.0.3:3000 ! -i docker0' failed: iptables: No chain/target/match by that name.

最佳答案

系统上的某些内容已删除了它需要工作的docker iptables条目。已建议here进行两个修复:

对于CentOS:

sudo service docker restart
sudo service iptables save

对于Ubuntu:
sudo apt-get install iptables-persistent
sudo service docker restart
iptables-save > /etc/iptables/rules.v4 # you may need to "sudo -s" to get a root shell first

重新启动docker之后,您应该在nat表下看到docker链:
iptables -t nat -vL

关于node.js - 映射Docker端口失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37679691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com