DockerFile:启动后如何获取bash命令行? [英] DockerFile : how to get bash command line after start?

查看:1101
本文介绍了DockerFile:启动后如何获取bash命令行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


这个问题不重复,因为我想获取一个交互式shell,而不用-it标志运行。


我正在向Docker移动第一步,以创建仅供内部使用的图像。



从这个 envirornment_full.df

  FROM ubuntu:16.04 
ENTRYPOINT [/ bin / bash]

然后我建立

  docker rmi environment:full 
docker build -t environment:full -f environment.df。

然后运行

 code> docker运行环境:full 

运行 docker images -a m我看到我的形象

  REPOSITORY TAG IMAGE ID创建大小
环境满aa91bbd39167 4秒前129 MB

所以我运行它

  docker运行环境:full 

我没有发现任何事情。 ...

  $ docker ps -a 
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5847c0a18f30环境:full/ bin / bash21秒前已退出(0)20秒前admiring_mirzakhani

/ p>

  $ docker运行环境:full -ti 
bash:无法设置minal进程组(-1):设备不正确的ioctl
bash:此shell中没有作业控制
root @ aa768a585f33:/#exit

我想拥有ubuntu提示符,就像我在SSH连接一样。而没有用户的这个必须输入-i或-tty标志



我如何才能实现?

解决方案

<$ c $如果stdin关闭,c> bash 将不会运行 。如果您不提供 -i 标志, bash 将立即退出。所以当你...

  docker run environment:full 

... bash立即退出,所以你的容器退出。你会看到它,如果你运行 docker ps -a ,它显示已停止的容器。



bash 如果不附加到tty,则不会提供交互式提示。所以如果你要运行...

  coerk run -i environment:full 

...你会得到一个 bash shell,但没有提示或作业控制,或其他功能。您需要为Docker提供 -t 以分配一个tty设备。



您无法获得所需的内容而不在命令行上同时提供 -i -t 选项。



另一种方法是设置运行ssh守护进程的映像,并将人ssh放入容器。而不是表现为像SSH连接一样,它实际上是一个ssh会话。



另请注意:

  docker运行环境:full -ti 

不一样:

  docker run -it environment:full 

前者将在容器内运行 bash -ti ,而后者将 -i -t 选项到 docker运行。 p>

This question is not duplicated, because I want to obtain an interactive shell without running with -it flags.

I'm moving first steps into Docker to create images only for internal use.

I start from this envirornment_full.df:

FROM ubuntu:16.04
ENTRYPOINT ["/bin/bash"]

I then build

docker rmi environment:full
docker build -t environment:full  -f environment.df .

Then run

docker run environment:full

Running docker images -am I see my image

REPOSITORY          TAG                 IMAGE ID            CREATED         SIZE
environment         full                aa91bbd39167        4 seconds ago   129 MB

So I run it

docker run environment:full 

I see nothing happening ....

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED         STATUS                      PORTS               NAMES
5847c0a18f30        environment:full    "/bin/bash"         21 seconds ago  Exited (0) 20 seconds ago                       admiring_mirzakhani

Also

$ docker run environment:full -ti
bash: cannot set terminal process group (-1): Inappropriate ioctl for device
bash: no job control in this shell
root@aa768a585f33:/# exit

I'd like to have the ubuntu prompt, like if I was in a SSH connection. And this without user must enter -i or -tty flags.

How can I realize this?

解决方案

bash won't run at all if stdin is closed. If you don't provide the -i flag, bash will simply exit immediately. So when you...

docker run environment:full 

...bash exits immediately, and so your container exits. You would see it if you ran docker ps -a, which shows container that have stopped.

bash won't give you an interactive prompt if it's not attached to a tty. So if you were to run...

coerk run -i environment:full

...you would get a bash shell, but with no prompt, or job control, or other features. You need to provide -t for Docker to allocate a tty device.

You can't get what you want without providing both the -i and -t options on the command line.

An alternative would be to set up an image that runs an ssh daemon, and have people ssh into the container. Instead of behaving "like if I was in a SSH connection", it would actually be an ssh session.

Also, note that this:

docker run environment:full -ti

Is not the same as this:

docker run -it environment:full

The former will run bash -ti inside a container, while the latter passes the -i and -t options to docker run.

这篇关于DockerFile:启动后如何获取bash命令行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆