Не могу разрешить порт в контейнере Docker Ubuntu - PullRequest
1 голос
/ 05 июля 2019

Хотите разрешить порту говорить 4000. Ран:

root@66548e7316fc:/# sudo ufw allow 4000/tcp
WARN: initcaps
[Errno 2] iptables v1.6.1: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.

Skipping adding existing rule
Skipping adding existing rule (v6)
root@66548e7316fc:/# 

root@66548e7316fc:/# sudo ufw status
ERROR: problem running iptables: iptables v1.6.1: can't initialize iptables table `filter': Permission denied (you must be root)
Perhaps iptables or your kernel needs to be upgraded.


root@66548e7316fc:/# service ufw status
 * Firewall is not running...                                                                  [fail] 
root@66548e7316fc:/# sudo ufw reload
Firewall not enabled (skipping reload)
root@94d82c9ba002:/# sudo ufw enable
ERROR: problem running ufw-init
/lib/ufw/ufw-init: 118: /lib/ufw/ufw-init: modprobe: not found
/lib/ufw/ufw-init: 118: /lib/ufw/ufw-init: modprobe: not found
/lib/ufw/ufw-init: 118: /lib/ufw/ufw-init: modprobe: not found
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 12
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 12
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
iptables-restore v1.6.1: iptables-restore: unable to initialize table 'filter'

Error occurred at line: 1
Try `iptables-restore -h' or 'iptables-restore --help' for more information.
sysctl: setting key "net.ipv4.conf.all.accept_redirects": Read-only file system
sysctl: setting key "net.ipv4.conf.default.accept_redirects": Read-only file system
sysctl: setting key "net.ipv6.conf.all.accept_redirects": Read-only file system
sysctl: setting key "net.ipv6.conf.default.accept_redirects": Read-only file system
sysctl: setting key "net.ipv4.icmp_echo_ignore_broadcasts": Read-only file system
sysctl: setting key "net.ipv4.icmp_ignore_bogus_error_responses": Read-only file system
sysctl: setting key "net.ipv4.icmp_echo_ignore_all": Read-only file system
sysctl: setting key "net.ipv4.conf.all.log_martians": Read-only file system
sysctl: setting key "net.ipv4.conf.default.log_martians": Read-only file system

Problem loading ipv6 (skipping)
Problem running '/etc/ufw/before.rules'
Problem running '/etc/ufw/after.rules'
Problem running '/etc/ufw/user.rules'

root@94d82c9ba002:/# 
sudo ufw reload
Firewall not enabled (skipping reload)

Я уже root, как вы видите root@66548e7316fc:/# в приведенной выше командной строке.

1 Ответ

2 голосов
/ 05 июля 2019

Чтобы разрешить машине подключаться к порту контейнера, вы должны использовать свойство expose или ports Docker.

Инструкция EXPOSE информирует Docker о том, что контейнер прослушивает указанные сетевые порты во время выполнения. Вы можете указать, будет ли порт прослушиваться по TCP или UDP, и по умолчанию используется TCP, если протокол не указан.

из документации Докера .

Или с ports:

По умолчанию при создании контейнера он не публикует свои порты во внешнем мире. Чтобы сделать порт доступным для служб вне Docker или для контейнеров Docker, которые не подключены к сети контейнера, используйте флаг --publish или -p.

с здесь .

Также вы можете указать IP-адрес, на котором будет прослушивать этот порт:

docker run -p 127.0.0.1:4000:4000 my container 
...