我想在(centos:6
)Docker容器中为我的root用户.bashrc
。但是,当我运行我的容器时,我发现.bashrc
尚未获得。可以这样做吗?
我的构建命令:
...
RUN touch .bashrc
RUN echo "iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB" >> .bashrc
...
我的跑步命令:
docker run -it --cap-add=NET_ADMIN myImage /bin/bash
答案 0 :(得分:18)
原来我错误地添加了文件。它应该是Process.Start(@"C:\Program Files (x86)\Citrix\ICA Client\concentr.exe");
IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Citrix Connection Center");
SetForegroundWindow(windowPtr);
System.Threading.Thread.Sleep(1000); // The window takes about a second to load up
SendR();
IntPtr prefWindowPtr = FindWindowByCaption(IntPtr.Zero, "Citrix Receiver - Preferences");
SendMessage(prefWindowPtr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
IntPtr windowPtr = FindWindowByCaption(IntPtr.Zero, "Citrix Connection Center") //For some reason I need to find this handle again or it doesn't close the window
SendMessage(windowPtr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
,而不仅仅是/root/.bashrc
。将文件添加到正确的位置后,不需要运行命令或CMD。
构建
.bashrc
运行
...
ADD iptables /iptables
RUN touch /root/.bashrc \
&& cat iptables >> /root/.bashrc
...
答案 1 :(得分:3)
bash manpage表示在shell处于交互状态时会读取.bashrc
。因此,如果您想要一个读取-i
的bash,则需要使用root@host:~# echo 'echo this is .bashrc' > /tmp/bashrc
root@host:~# docker run -ti -v /tmp/bashrc:/root/.bashrc debian bash -i
this is .bashrc
root@01da3a7e9594:/#
启动bash。
看到:
bash -i
但是,在容器中执行这样的ExecutorService executorService = Executors.newFixedThreadPool(5);
List<Callable> tasks = ...
for (Callable task : tasks) {
executorService.submit(task);
}
executorService.shutdown();
try {
executorService.awaitTermination(1, TimeUnit.SECONDS);
} catch (Exception e) {
.. log exception
}
会覆盖入口点或cmd,因此最好将shelltables命令和最初使用的入口点包装在成为入口点/ cmd的shell脚本中