I also encountered this problem myself. But in a different situation, I hope that when docker runs, the container can always run in the background and allow me to log in remotely to operate.
I copied the article: SSH remote login to a container
----Content begins-----
After starting a container, we may need to log in using ssh to perform some operations. To achieve this goal, there are 2 points that need to be ensured:
Container must be running.
openssh-server is started.
注意:以下示例是在ubuntu/13.10中完成的
First make sure the image has openssh-serverservice
There are indeed some inconsistencies between the early and current official documents here. Now it is detach. The early documents say that -d is specified to run the container in daemon mode. There may be some misunderstandings.
In addition, if you need to run bash in the container, just run docker run -i -t CONTAINER_NAME /bin/bash directly. If you think there are more parameters than docker attach, you can set an alias to solve the problem:
alias dockerbash='docker run -i -t CONTAINER_ID /bin/bash'
After setting the alias, run dockerbash directly to enter the bash of the container.
It can be achieved using supervisor. And you can start multiple services at the same time.
First install the software package with yum -y install supervisor and modify the configuration file /etc/supervisord.conf
Add the services you want to start, such as sshd.
For specifics, you can refer to this article: http://openstack.blog.163.com/blog/static/236387267201491734019283/
It is recommended to add a sentence to the Dockerfile file for building the image: CMD tail -f If there are other commands CMD other commands && tail -f I hope it will be helpful to you
I also encountered this problem myself. But in a different situation, I hope that when docker runs, the container can always run in the background and allow me to log in remotely to operate.
I copied the article: SSH remote login to a container
----Content begins-----
After starting a container, we may need to log in using ssh to perform some operations. To achieve this goal, there are 2 points that need to be ensured:
First make sure the image has
installedopenssh-server
serviceThen, submit the image:
Finally, run the image and let the generated container run in the background:
Now, you can log into the container via ssh.
docker run
指定的命令如果不是那些一直挂起的命令(比如运行top
,不断echo
),就是会自动退出的。-d
命令是设置detach为true,根据官方的文档,意思是让这个命令在后台运行,但并不是一直运行(我们在一个正常的Linux Terminal中运行/bin/bash
,运行完了也就完了,不会一直挂着等待响应的,所以确实没办法用daemon方式来跑/bin/bash
).There are indeed some inconsistencies between the early and current official documents here. Now it is detach. The early documents say that -d is specified to run the container in daemon mode. There may be some misunderstandings.
In addition, if you need to run bash in the container, just run
docker run -i -t CONTAINER_NAME /bin/bash
directly. If you think there are more parameters than docker attach, you can set an alias to solve the problem:After setting the alias, run
dockerbash
directly to enter the bash of the container.It can be achieved using supervisor. And you can start multiple services at the same time.
First install the software package with yum -y install supervisor and modify the configuration file /etc/supervisord.conf
Add the services you want to start, such as sshd.
For specifics, you can refer to this article: http://openstack.blog.163.com/blog/static/236387267201491734019283/
docker run --attach=stdin -d image bash, the -d parameter turns off stdin by default.
It is recommended to add a sentence to the Dockerfile file for building the image:
CMD tail -f
If there are other commands
CMD other commands && tail -f
I hope it will be helpful to you