不能使用SSH连接到docker容器 [英] Not able to connect to docker containers using SSH
问题描述
这是我的Docker文件:
FROM ubuntu:12.04
pre>
RUN apt-get更新
运行apt-get install -y apache2& openssh-server
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR / var / log / apache2
EXPOSE 80
EXPOSE 22
ENTRYPOINT [/ usr / sbin / apache2]
CMD [-D,FOREGROUND]
然后我运行这个cmd:
docker build -t =apache2。
$ docker run -d apache2
当我做
docker ps
,我可以看到端口被分配,但是我无法使用ssh连接到该容器。
$ docker ps
ID IMAGE COMMAND CREATED STATUS PORTS
5765535796f8 apache2:最新/ usr / sbin / apache2 -D大约一分钟前关于a分49154-> 80,49155-> 22
解决方案
运行apt-get install -y apache2& openssh-server
应该是
-get install -y apache2 openssh-server
如果您更改此选项,以及添加步骤设置root密码,如运行ssh服务指南是否可以将ssh插入运行容器?
https://docs.docker.com/engine/examples/running_ssh_service/
I am new to Docker, I built the container from a Dockerfile, and I can see the container creating and running, but I am not able to connect to that container using ssh.
Here is my Dockerfile:
FROM ubuntu:12.04 RUN apt-get update RUN apt-get install -y apache2 & openssh-server ENV APACHE_RUN_USER www-data ENV APACHE_RUN_GROUP www-data ENV APACHE_LOG_DIR /var/log/apache2 EXPOSE 80 EXPOSE 22 ENTRYPOINT ["/usr/sbin/apache2"] CMD ["-D", "FOREGROUND"]
Then I ran this cmd:
docker build -t="apache2" . $ docker run -d apache2
When I do
docker ps
, I can see the port is assigned, but I am not able to connect to that container using ssh.$ docker ps
ID IMAGE COMMAND CREATED STATUS PORTS 5765535796f8 apache2:latest /usr/sbin/apache2 -D About a minute ago Up About a minute 49154->80,49155->22
解决方案It looks like there's a typo in your docker file. Line:
RUN apt-get install -y apache2 & openssh-server
should be
RUN apt-get install -y apache2 openssh-server
If you change this as well as add the steps to setting the root password as shown in the "running an ssh service guide" are you able to ssh into your running container?
https://docs.docker.com/engine/examples/running_ssh_service/
这篇关于不能使用SSH连接到docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!