我无法在 docker bash 终端中执行 netcat 命令?
I am unable to execute netcat command within docker bash terminal?
我是 docker 的初学者。
我已经使用命令
sudo apt install docker-ce
在我的 ubuntu 18.04 机器上安装了 docker-ce
作为教程的一部分,我试图通过执行以下一系列命令在容器之间建立连接。
Below command will turn on ports 1234/4321 to listen to traffic inside/outside of containers i'm going to use.
root@ghost-SVE9999CNS:/home/ghost# docker run --rm -ti -p 1234:1234 -p 4321:4321 --name echo-server ubuntu:18.04 bash
Now, I wanted to run netcat commands within docker bash terminal.
root@xxxyyyyzzzz12:/# nc -lp 1234 | nc -lp 4321
一旦我从我的终端输入上面的命令..它给出错误 "nc: command not found"
bash: nc: command not found
bash: nc: command not found
后来,我做了足够的研究,但我从未找到任何官方docker解决这个问题的方法。
谁能帮我在 docker-ce.
中安装 netcat
我试过如下命令。
apt-get install netstat
apt-get install nc
但是,运气不好。
nc
默认情况下未安装在 ubuntu:18.04
图像上,因此您必须安装它:
apt-get update && apt-get install -y netcat
apt-get update
是第一次更新包列表所必需的(当容器启动时,此列表为空)。完成后,您可以从容器中 运行 nc -lp 1234
。
如需测试所有作品,您可以:
- 运行 来自 shell(在您的主机上)类似于
telnet container_ip 1234
或 telnet localhost 1234
(因为端口已被转发)
- 输入内容
- 查看容器输出以查看您在主机中键入的内容shell
不需要使用ubuntu:18.04
来按照教程进行,您可以使用ubuntu:14.04
,例如默认安装nc
。
docker run --rm -ti -p 1234:1234 -p 4321:4321 --name echo-server ubuntu:14.04 bash
我是 docker 的初学者。
我已经使用命令sudo apt install docker-ce
在我的 ubuntu 18.04 机器上安装了 docker-ce
作为教程的一部分,我试图通过执行以下一系列命令在容器之间建立连接。
Below command will turn on ports 1234/4321 to listen to traffic inside/outside of containers i'm going to use.
root@ghost-SVE9999CNS:/home/ghost# docker run --rm -ti -p 1234:1234 -p 4321:4321 --name echo-server ubuntu:18.04 bash
Now, I wanted to run netcat commands within docker bash terminal.
root@xxxyyyyzzzz12:/# nc -lp 1234 | nc -lp 4321
一旦我从我的终端输入上面的命令..它给出错误 "nc: command not found"
bash: nc: command not found
bash: nc: command not found
后来,我做了足够的研究,但我从未找到任何官方docker解决这个问题的方法。
谁能帮我在 docker-ce.
中安装 netcat
我试过如下命令。
apt-get install netstat
apt-get install nc
但是,运气不好。
nc
默认情况下未安装在 ubuntu:18.04
图像上,因此您必须安装它:
apt-get update && apt-get install -y netcat
apt-get update
是第一次更新包列表所必需的(当容器启动时,此列表为空)。完成后,您可以从容器中 运行 nc -lp 1234
。
如需测试所有作品,您可以:
- 运行 来自 shell(在您的主机上)类似于
telnet container_ip 1234
或telnet localhost 1234
(因为端口已被转发) - 输入内容
- 查看容器输出以查看您在主机中键入的内容shell
不需要使用ubuntu:18.04
来按照教程进行,您可以使用ubuntu:14.04
,例如默认安装nc
。
docker run --rm -ti -p 1234:1234 -p 4321:4321 --name echo-server ubuntu:14.04 bash