【发布时间】:2019-09-11 11:53:55
【问题描述】:
我无法访问 SSH 或 HTTP-alt。 Ubuntu 容器在 MacOSX 上运行。出于同样的原因,我认为 SSH 和 HTTP-alt 都有问题。我正在使用 dockerfile 和 docker-compose 进行设置。因为我是docker新手,可能会有多余的命令。我的主机禁用了防火墙。
码头文件
<-- output omitted for brevity -->
# ports
EXPOSE 22 8080
码头工人撰写
version: '3'
services:
base:
image: cox-nams:1.0
container_name: cox-nams
hostname: neteng-docker
stdin_open: true
ports:
- "10000:22" # ssh
- "10001:8080" # jupyter
<-- output omitted for brevity -->
初始化命令
$ docker exec -it cox-nams /bin/bash
Docker 输出
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b37789c4660c ba397d1c07cd "/bin/sh -c 'service…" 34 minutes ago Up 34 minutes 0.0.0.0:10000->22/tcp, 0.0.0.0:10001->8080/tcp cox-nams
容器内的端口
duser@neteng-docker:~$ netstat -at | grep LISTEN
tcp 0 0 0.0.0.0:http-alt 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.11:46461 0.0.0.0:* LISTEN
tcp6 0 0 [::]:ssh [::]:* LISTEN
容器内的 SSH
duser@neteng-docker:~$ ssh duser@localhost -p 22
The authenticity of host 'localhost (127.0.0.1)' can't be established.
ECDSA key fingerprint is SHA256:la2X7X8gZj7t8DQC7rwHTalMBHYC9oVggfYzATuzkyM.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
duser@localhost's password:
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 4.14.134-boot2docker x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
Last login: Fri Aug 30 18:38:54 2019 from 127.0.0.1
duser@neteng-docker:~$
来自主机的 SSH
$ ssh duser@localhost -p 10000
ssh: connect to host localhost port 10000: Connection refused
服务
root@neteng-docker:/# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 03:37 ? 00:00:00 /bin/sh -c service ssh restart && bash
root 18 1 0 03:37 ? 00:00:00 /usr/sbin/sshd
root 19 1 0 03:37 ? 00:00:00 bash
root 20 0 0 03:37 pts/0 00:00:00 /bin/bash
root 55 20 0 03:40 pts/0 00:00:00 ps -ef
root@neteng-docker:/# service --status-all
[ - ] dbus
[ ? ] hwclock.sh
[ - ] procps
[ + ] ssh
编辑:添加服务输出
【问题讨论】:
-
容器运行时为什么不使用
docker exec -it cox-nams bash? -
EXPOSE'ing 端口没问题,但容器内实际运行的是哪些服务? -
@Stefano 因为我希望其他人可以通过网络直接访问此容器。
-
@masseyb 已将服务信息添加到帖子
-
你能在你的主机上试试
ssh duser@0.0.0.0 -p 10000吗?