2016-05-17 34 views
9

Desidero fornire l'utente root in un contenitore (centos:6) al .bashrc. Tuttavia, quando eseguo il mio contenitore, trovo che lo .bashrc non è stato acquistato. Può essere fatto?Come .bashrc per root nella finestra mobile

mio comando build:

... 
RUN touch .bashrc 
RUN echo "iptables -t nat -A OUTPUT -d hostA -p tcp --dport 3306 -j DNAT --to hostB" >> .bashrc 
... 

mio comando di marcia:

docker run -it --cap-add=NET_ADMIN myImage /bin/bash 
+0

provare a mettere i comandi 2 in un 'cmd' separati da un', 'e ricostruire/rilanciare – user2915097

+0

Quindi, se lo faccio ed eseguirlo senza la parte '/ bin/bash' del comando run, viene eseguito ma non mi dà il controllo interattivo del contenitore. –

+0

Voglio dire, quando la tua nuova immagine è stata creata, allora 'docker run -it --cap-add = NET_ADMIN mynewimage/bin/bash' – user2915097

risposta

5

Sembra che stavo aggiungendo il file in modo errato. Dovrebbe essere /root/.bashrc anziché solo .bashrc. Con il file aggiunto nella posizione corretta, non è richiesto alcun comando di esecuzione o CMD.

Corporatura

... 
ADD iptables /iptables 
RUN touch /root/.bashrc \ 
&& cat iptables >> /root/.bashrc 
... 

Run

docker run -it --cap-add=NET_ADMIN myImage /bin/bash 
0

La pagina di manuale bash afferma che .bashrc si legge wheb la shell è interattiva. Quindi, se vuoi una bash che legge .bashrc, devi lanciare bash con -i.

Vedere che:

[email protected]:~# echo 'echo this is .bashrc' > /tmp/bashrc 
[email protected]:~# docker run -ti -v /tmp/bashrc:/root/.bashrc debian bash -i 
this is .bashrc 
[email protected]:/# 

Ma, eseguendo bash -i come questo nel contenitore, sostituisce l'entrypoint o cmd, per cui si potrebbe essere meglio con avvolgendo il comando iptables e l'entrypoint si sono originariamente utilizzando in un guscio script che diventa il tuo entrypoint/cmd.

Problemi correlati