[英]How to docker exec a shell builtin of docker container specifically on Ubuntu docker image/container
thank you for reading my post. 感谢您阅读我的帖子。
Problem: 问题:
# docker ps
CONTAINER ID IMAGE COMMAND
35c8b832403a ubuntu1604:1 "sh -c /bin/sh"
# docker exec -i -t 35c8b832403a type type
rpc error: code = 2 desc = oci runtime error: exec failed: container_linux.go:262: starting container process caused "exec: \"type\": executable file not found in $PATH"
# Dockerfile
FROM ubuntu:16.04
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
RUN apt-get update && apt-get -y upgrade
ENTRYPOINT ["sh", "-c"]
CMD ["/bin/bash"]
Description: 描述:
My objective is to get "type" shell builtin been execute in a way of writing docker exec as below 我的目标是通过编写docker exec的方式使内置的“类型” shell得以执行,如下所示
docker exec -i -t 35c8b832403a type type (FAILED) docker exec -i -t 35c8b832403a类型类型(FAILED)
NOT 不
docker exec -i -t 35c8b832403a sh -c "type type" (PASSED) 泊坞窗exec -i -t 35c8b832403a sh -c“类型类型”(通过)
I have googling around, do some modification in the container (change /etc/profile, /etc/environment, bashrc) but failed. 我四处搜寻,在容器中进行了一些修改(更改/ etc / profile,/ etc / environment,bashrc),但是失败了。
From the docker documentation itself, it has state that: 从docker文档本身来看,它的状态是:
COMMAND will run in the default directory of the container.
COMMAND将在容器的默认目录中运行。 It the underlying image has a custom directory specified with the WORKDIR directive in its Dockerfile, this will be used instead.
如果基础映像具有在其Dockerfile中使用WORKDIR指令指定的自定义目录,则将使用该目录。
COMMAND should be an executable, a chained or a quoted command will not work.
COMMAND应该是可执行文件,链式命令或带引号的命令将不起作用。 Example: docker exec -ti my_container "echo a && echo b" will not work, but docker exec -ti my_container sh -c "echo a && echo b" will.
示例:docker exec -ti my_container“ echo a && echo b”不起作用,但是docker exec -ti my_container sh -c“ echo a && echo b”将起作用。
But seem it IS POSSIBLE when I able to get the right output FROM DOCKER FEDORA (Dockerfile: FROM fedora:25) 但是当我能够从DOCKER FEDORA获得正确的输出时,这似乎是可能的 (Dockerfile:FROM fedora:25)
# docker ps
CONTAINER ID IMAGE COMMAND
2a17b2338518 fedora25:1 "sh -c /bin/sh"
# docker exec -i -t 2a17b2338518 type type
type is a shell builtin
Question: 题:
Is there any way to enable this on Ubuntu docker? 有什么办法可以在Ubuntu docker上启用它吗? Image/Container tweaks?
图像/容器调整? Vagrantfile Configuration?
Vagrantfile配置? Please help.
请帮忙。
Others: 其他:
Using docker run, I able to get the right output because of the "ENTRYPOINT" in the Dockerfile. 使用docker run,由于Dockerfile中的“ ENTRYPOINT”,我能够获得正确的输出。 However the image need to be save instead of export .
但是, 该图像需要保存而不是导出 。
CMD and ENTRYPOINT are meaningless if you run docker exec
. 如果您运行docker
docker exec
则CMD和ENTRYPOINT毫无意义。 The remaining arguments are taken as the command and executed inside the already existing container. 其余参数用作命令并在现有容器中执行。
Maybe you wanted to use docker run
? 也许您想使用
docker run
?
Just in case, to be able to execute type as you expect, it would need to be part of the path. 以防万一,为了能够按预期执行类型,它需要成为路径的一部分。 Being a shell builtin wouldn't help because as you said, you don't want to execute
/bin/bash -c 'type type'
像您所说的那样,内置的shell并没有帮助,因为您不想执行
/bin/bash -c 'type type'
If you want to have type
executed as a builtin shell command, this means you need to execute a shell /bin/bash
or /bin/sh
and then execute 'type type' on it, making it /bin/bash -c 'type type'
如果您希望将
type
作为内置的shell命令执行,这意味着您需要执行一个shell /bin/bash
或/bin/sh
,然后对其执行'type type',使其成为/bin/bash -c 'type type'
After all, as @Henry said, docker exec is a the full command that will be executed and there is no place for CMD
or ENTRYPOINT
on it. 毕竟,正如@Henry所说,docker exec是将要执行的完整命令,并且在其上没有放置
CMD
或ENTRYPOINT
位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.