从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引用非const对象(const reference to non-const object)

没有。 引用仅仅是现有对象的别名。 const由编译器强制执行; 它只是检查你是否试图通过引用r修改对象。 *这不需要创建副本。 鉴于const只是编译器强制执行“只读”的一条指令,那么为什么最终的示例不能编译,应该马上明白。 如果你可以通过对一个const对象进行非const引用来轻易地规避它, const将毫无意义。 *当然,你仍然可以通过x修改对象。 任何更改也将通过r可见,因为它们指向同一个对象。 No. A reference is simply an alias for an exis...

之前的const还是const之后?(Const before or const after?)

“为什么有两种正确的方式来指定const数据,在什么情况下你会喜欢或需要一个超过另一个呢? 基本上,在星号之前的const中的const的位置不重要的原因在于C语法是由Kernighan和Ritchie定义的。 他们以这种方式定义语法的原因很可能是它们的C编译器从左到右分析输入,并在完成处理每个令牌时消耗它。 使用*令牌将当前声明的状态更改为指针类型。 表示const限定符应用于指针声明; 在*之前遇到它意味着将限定符应用于指向的数据。 因为如果const限定符出现在类型说明符之前或之后,语义的意...

当容器在C ++中是const时,如何对容器持有的对象进行非const访问(How to have non-const access to object held by a container when the container is const in C++)

您需要在每个不具有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].dataN...

Const和非const c ++构造函数(Const and non-const c++ constructor)

不,不是你想要使用它的方式。 在编译时具有不同行为的唯一方法是使用不同的类型。 但是,您可以使用起来相当容易: #include <stdio.h> template <typename T> class SometimesConst { public: SometimesConst(T* buffer) : buffer(buffer) { } T* get() { return buffer; } void increment() { ++counter; } ...

当函数接受对象的引用(并访问非const方法)时,如何抛弃const'ness?(How do you cast away const'ness when the function takes a reference to the object (and access non-const methods)?)

请注意,如果你这样做并且对象确实是const ,那么在抛弃const之后修改它是未定义的行为。 fgBlocks.CopyInto(const_cast<BlkArray&>(backUpCopy)); 另一个是同样的事情: const_cast<BlkArray&>(backUpCopy).RemoveAll(true); Be aware that if you do this and the object really is const, then modifying it after ...

将相同的对象作为const和非const引用传递(Pass same object as const and non-const reference)

因为编译器将这两个参数视为不同的引用,所以没有问题。 要理解代码,请考虑以下示例 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 consi...

修改const对象的非const成员(Modifying non-const members of const object)

使用const_cast修改const数据结构中的数据确实是未定义的行为。 例外情况是标记为mutable项目。 这些值的重点在于,即使对象的其余部分是const ,它们也是可修改的。 它的确意味着“但这个不是const ”。 由于几乎所有的const都是关于编译器检测修改的,尽管从技术上讲,编译器允许在“不可写的内存”中放置一些const变量。 mutable关键字允许“绕过” const ,因此编译器不会将const对象放入不可写的内存中(如果它有可变组件),当然,它不会“对象”到const在...

将const成员函数转换为非const(Cast const member function to non-const)

编译器吃了它。 但落后演员更有用。 而且 - 最好不要使用它,const_cast通常只是一个快速而肮脏的解决方案,只有在没有任何其他解决方案时才应用。 回答更新 如果我理解正确,你将使用一个对象和两个函数。 第一个函数接受const对象和const成员函数,第二个函数接受非const对象和非const成员函数。 根据给定的信息,您可以更改第二个函数以接受非const对象和const成员函数。 并给它们一个非const对象及其const成员函数。 Compiler eats it. But the...

constexpr对非const对象的引用(constexpr reference to non-const object)

假设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 con...

在const对象上间接调用非const函数(Indirectly calling non-const function on a const object)

是的,根据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...

相关文章

更多

Docker 容器创建并运行MySQL

下载MySQL镜像:docker pull centos/mysql‐57‐centos7(docke ...

揭开Docker神秘的面纱-传智播客Docker视频教程

Docker是基于LXC的虚拟化技术,它为IT行业中的运维人员和开发人员都带来了非常大的帮助,对于运维 ...

storm client command

最近在研究实时日志分析,storm确实不错,以下是命令参数: storm help Syntax: ...

bash: scp: command not found的解决方法

# scp -bash: scp: command not found 查看系统是否已经安装了scp ...

Running Solr with Maven

Solris an open source search server which is built ...

solr 建立索引 命令

Next we have a Solr query to start the indexing pro ...

Shell命令格式

Shell命令由两部分组成:一个是Shell提示符,另一个是命令,Command –Options A ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本