首页 \ 问答 \ 从docker容器运行docker命令(Running docker command from docker container)

从docker容器运行docker命令(Running docker command from docker container)

需要编写一个在dock-a中安装docker的Dockerfile。 因为container-a需要执行docker命令到container-b,它与container-a一起运行。 我的理解是你在编写Dockerfile时不应该使用“sudo”。 但我陷入困境 - 我指派给docker组的用户是什么? 当您运行docker exec -it ,您将自动为root。

sudo usermod -a -G docker whatuser?

另外(我在集装箱内手动尝试这个 - 看它是否有效)你必须做一个newgrp docker来激活对组的更改。 我这样做的任何时候,当我没有sudo'ed时,我最终sudo'ing。 那有意义吗? 症状是 - 我去exit容器,我必须退出两次(好像我改变了用户)。

我究竟做错了什么?


Need to write a Dockerfile that installs docker in container-a. Because container-a needs to execute a docker command to container-b that's running alongside container-a. My understanding is you're not supposed to use "sudo" when writing the Dockerfile. But I'm getting stuck -- what user to I assign to docker group? When you run docker exec -it, you are automatically root.

sudo usermod -a -G docker whatuser?

Also (and I'm trying this out manually inside container-a to see if it even works) you have to do a newgrp docker to activate the changes to groups. Anytime I do that, I end up sudo'ing when I haven't sudo'ed. Does that make sense? The symptom is -- I go to exit the container, and I have to exit twice (as if I changed users).

What am I doing wrong?


原文:https://stackoverflow.com/questions/42237352
更新时间:2023-09-09 16:09

最满意答案

使用const_cast修改const数据结构中的数据确实是未定义的行为。 例外情况是标记为mutable项目。 这些值的重点在于,即使对象的其余部分是const ,它们也是可修改的。 它的确意味着“但这个不是const ”。

由于几乎所有的const都是关于编译器检测修改的,尽管从技术上讲,编译器允许在“不可写的内存”中放置一些const变量。 mutable关键字允许“绕过” const ,因此编译器不会将const对象放入不可写的内存中(如果它有可变组件),当然,它不会“对象”到const在它的可变组件中修改的对象 - 甚至在const函数内部。


Using const_cast to modify data in a const data structure is indeed undefined behaviour. The exception is items marked mutable. The whole point of these values are that they are modifiable even when the rest of the object is const. It really means "but this one is not const".

Since nearly all of const is about the compiler detecting modification, although technically, the compiler is allowed place some const variables in "non-writeable memory". The mutable keyword is there to allow "bypass" of the constness, so the compiler will NOT put a const object into memory that is non-writeable if it has a mutable component, and of course, it won't "object" to const objects being modified in it's mutable components - even inside a const function.

相关问答

更多
  • 没有。 引用仅仅是现有对象的别名。 const由编译器强制执行; 它只是检查你是否试图通过引用r修改对象。 *这不需要创建副本。 鉴于const只是编译器强制执行“只读”的一条指令,那么为什么最终的示例不能编译,应该马上明白。 如果你可以通过对一个const对象进行非const引用来轻易地规避它, const将毫无意义。 *当然,你仍然可以通过x修改对象。 任何更改也将通过r可见,因为它们指向同一个对象。 No. A reference is simply an alias for an existing ...
  • “为什么有两种正确的方式来指定const数据,在什么情况下你会喜欢或需要一个超过另一个呢? 基本上,在星号之前的const中的const的位置不重要的原因在于C语法是由Kernighan和Ritchie定义的。 他们以这种方式定义语法的原因很可能是它们的C编译器从左到右分析输入,并在完成处理每个令牌时消耗它。 使用*令牌将当前声明的状态更改为指针类型。 表示const限定符应用于指针声明; 在*之前遇到它意味着将限定符应用于指向的数据。 因为如果const限定符出现在类型说明符之前或之后,语义的意义不会改变 ...
  • 您需要在每个不具有const访问权限的地方排除const修饰符: containerVec_t & outputVars() { return _outputVars; } //Change definition in MiddleMan class MiddleMan::containerVec_t & outputs = theMiddleMan.outputVars(); //Change reference type float * data_ptr = outputs[0].dataNonCon ...
  • 不,不是你想要使用它的方式。 在编译时具有不同行为的唯一方法是使用不同的类型。 但是,您可以使用起来相当容易: #include template class SometimesConst { public: SometimesConst(T* buffer) : buffer(buffer) { } T* get() { return buffer; } void increment() { ++counter; } priv ...
  • 请注意,如果你这样做并且对象确实是const ,那么在抛弃const之后修改它是未定义的行为。 fgBlocks.CopyInto(const_cast(backUpCopy)); 另一个是同样的事情: const_cast(backUpCopy).RemoveAll(true); Be aware that if you do this and the object really is const, then modifying it after casti ...
  • 因为编译器将这两个参数视为不同的引用,所以没有问题。 要理解代码,请考虑以下示例 int i = 10; const int &cr = i; int &r = i; r = 20; std::cout << cr << std::endl; There is no problem becuase the compiler consideres these two parameters as different references. To understand the code consider t ...
  • 使用const_cast修改const数据结构中的数据确实是未定义的行为。 例外情况是标记为mutable项目。 这些值的重点在于,即使对象的其余部分是const ,它们也是可修改的。 它的确意味着“但这个不是const ”。 由于几乎所有的const都是关于编译器检测修改的,尽管从技术上讲,编译器允许在“不可写的内存”中放置一些const变量。 mutable关键字允许“绕过” const ,因此编译器不会将const对象放入不可写的内存中(如果它有可变组件),当然,它不会“对象”到const在它的可变组 ...
  • 编译器吃了它。 但落后演员更有用。 而且 - 最好不要使用它,const_cast通常只是一个快速而肮脏的解决方案,只有在没有任何其他解决方案时才应用。 回答更新 如果我理解正确,你将使用一个对象和两个函数。 第一个函数接受const对象和const成员函数,第二个函数接受非const对象和非const成员函数。 根据给定的信息,您可以更改第二个函数以接受非const对象和const成员函数。 并给它们一个非const对象及其const成员函数。 Compiler eats it. But the back ...
  • 假设x具有静态存储持续时间,则左值表达式x是完全有效的常量表达式。 如果在需要prvalue的上下文中使用x ,这会导致将lvalue-to-rvalue转换应用于它,那么生成的prvalue表达式 - 称之为TO_RVALUE(x) - 将不是常量表达式,原因显而易见。 但是在引用绑定的情况下,没有这样的转换。 Assuming that x has static storage duration, the lvalue expression x is a perfectly valid constant ...
  • 是的,根据7.1.5.1/4,这是未定义的行为: 除了可以修改任何声明mutable的类成员(7.1.1)外,任何在其生命周期(3.8)期间修改const对象的尝试都会导致未定义的行为。 请注意,当构造函数调用完成时(3.8 / 1),对象的生存期开始。 Yes, it is undefined behavior, as per 7.1.5.1/4: Except that any class member declared mutable (7.1.1) can be modified, any atte ...

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)