Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:docker-advanced [2019/07/12 16:57] alfred [Environment variables] |
wiki2:docker-advanced [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 83: | Línea 83: | ||
| docker cp c:\myfolder\myfile.txt dummy:/root/myfile.txt | docker cp c:\myfolder\myfile.txt dummy:/root/myfile.txt | ||
| docker rm dummy | docker rm dummy | ||
| + | </code> | ||
| + | |||
| + | ==== Creación de un volumen mapeado en nfs (docker-compose) ==== | ||
| + | <code yml> | ||
| + | volumes: | ||
| + | nas-owncloud: | ||
| + | driver: local | ||
| + | driver_opts: | ||
| + | type: nfs | ||
| + | o: "addr=10.10.10.10,nolock,soft,rw" | ||
| + | device: ":/volume1/sir-vices/owncloud" | ||
| + | |||
| + | services: | ||
| + | owncloud: | ||
| + | volumes: | ||
| + | - nas-owncloud:/mnt/data | ||
| </code> | </code> | ||
| ===== Compose ===== | ===== Compose ===== | ||
| Línea 136: | Línea 152: | ||
| ===== Execute GUI programs ===== | ===== Execute GUI programs ===== | ||
| + | |||
| + | You can create a Dockerfile where you install a Firefox, a Visual Studio Code... Whatever. Then, as the X11 Linux programs work like client\server you only need to bind the socket. \\ | ||
| + | For example, a Dockerfile could be this: | ||
| + | <code> | ||
| + | FROM ubuntu:14.04 | ||
| + | RUN apt-get update && apt-get install -y firefox | ||
| + | |||
| + | RUN export uid=1000 gid=1000 && \ | ||
| + | mkdir -p /home/developer && \ | ||
| + | echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \ | ||
| + | echo "developer:x:${uid}:" >> /etc/group && \ | ||
| + | echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \ | ||
| + | chmod 0440 /etc/sudoers.d/developer && \ | ||
| + | chown ${uid}:${gid} -R /home/developer | ||
| + | |||
| + | USER developer | ||
| + | ENV HOME /home/developer | ||
| + | |||
| + | CMD /usr/bin/firefox | ||
| + | </code> | ||
| + | |||
| + | Then you only need to buid it: | ||
| + | <code> | ||
| + | docker build -t firefox . | ||
| + | </code> | ||
| + | |||
| + | And launch it using your x11 socket: | ||
| + | <code> | ||
| + | docker run -ti --rm \ | ||
| + | -e DISPLAY=$DISPLAY \ | ||
| + | -v /tmp/.X11-unix:/tmp/.X11-unix \ | ||
| + | firefox | ||
| + | </code> | ||
| + | |||
| + | You could also use the run with the cmd as parameter, in this way you could install several programs and launch them with this. | ||
| + | |||
| + | ==== Launch them from SSH ==== | ||
| + | |||
| + | |||
| + | As it says here [[https://docs.docker.com/engine/examples/running_ssh_service/]] you can create a Dockerfile with... | ||
| + | <code> | ||
| + | FROM ubuntu:16.04 | ||
| + | |||
| + | RUN apt-get update && apt-get install -y openssh-server | ||
| + | RUN mkdir /var/run/sshd | ||
| + | RUN echo 'root:THEPASSWORDYOUCREATED' | chpasswd | ||
| + | RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config | ||
| + | |||
| + | # SSH login fix. Otherwise user is kicked off after login | ||
| + | RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd | ||
| + | |||
| + | ENV NOTVISIBLE "in users profile" | ||
| + | RUN echo "export VISIBLE=now" >> /etc/profile | ||
| + | |||
| + | EXPOSE 22 | ||
| + | CMD ["/usr/sbin/sshd", "-D"] | ||
| + | </code> | ||
| + | ... for an ssh server. | ||
| + | |||
| + | This one will be prepared for launching a remote firefox in your local machine if you connect to it via ssh and launch it. | ||
| + | <code> | ||
| + | FROM ubuntu:14.04 | ||
| + | |||
| + | RUN apt-get update && apt-get install -y firefox openssh-server | ||
| + | RUN mkdir /var/run/sshd | ||
| + | RUN echo 'root:train' | chpasswd | ||
| + | RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config | ||
| + | |||
| + | # SSH login fix. Otherwise user is kicked off after login | ||
| + | RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd | ||
| + | |||
| + | ENV NOTVISIBLE "in users profile" | ||
| + | RUN echo "export VISIBLE=now" >> /etc/profile | ||
| + | RUN echo "X11UseLocalhost no" >> /etc/ssh/sshd_config | ||
| + | |||
| + | EXPOSE 22 | ||
| + | CMD ["/usr/sbin/sshd", "-D"] | ||
| + | # CMD tail -f /dev/null | ||
| + | </code> | ||
| + | |||