在Ubuntu上从docker容器访问主机端口时出错

我试图从一个运行OCaml栈的docker容器中访问一个主机端口。 当运行容器时使用--net=host选项时,出现以下错误

 Fatal error: exception # opam-version 1.2.2 (58ef3b8213100953848d362f7120a30356d7f77d) # os linux opam: "execvp" failed on --net=host: No such file or directory 

我的/etc/hosts文件的内容如下

 127.0.0.1 localhost 127.0.1.1 ubuntu # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 

有人可以解释为什么我可以得到这个错误?

编辑

我使用的docker run -it <repo-name> --net=host命令是docker run -it <repo-name> --net=host

Docker参数需要在容器名称前面列出。 否则,它们被解释为容器入口点的参数。 这应该工作:

 docker run -it --network=host <repo-name>