Docker: intel·ligència artificial - IOC
Salta a la navegació
Salta a la cerca
Contingut
Introducció
En el marc dels Cursos d'Especialització s'hauria de proporcionar una màquina docker oficial als alumnes, que inclogui totes les llibreries necessàries. S'ha de documentar el procés de creació d'aquest docker, i s'haurà de versionar, doncs anirà canviant els requeriments (i actualitzant les versions de les llibreries).
Imatge oficial de Pytorch
Completar el docker amb llibreries
Jupyter
Primer exemple amb Pytorch
Pujar/publicar el docker a dockerhub
Testejar el docker a una màquina Windows
Dockerfile_1_0
scripts
Dockerfile_1_0
FROM pytorch/pytorch RUN apt-get update && \ apt-get install -y nano && \ apt-get install -y joe COPY ./requirements_1_0.txt . RUN pip3 install --no-cache-dir -r requirements_1_0.txt COPY ./arrencar_jupyter.sh . RUN chmod a+x arrencar_jupyter.sh # Add user dockeria RUN useradd -ms /bin/sh dockeria RUN usermod -aG sudo dockeria RUN mv arrencar_jupyter.sh /home/dockeria USER dockeria # Set working directory WORKDIR /home/dockeria # shared folder RUN mkdir shared_folder # Mòdul M3 RUN mkdir M3 RUN mkdir M3/data COPY ./data/* M3/data/ RUN mkdir M3/test COPY ./test/* M3/test/ # Set working directory to M3 WORKDIR /home/dockeria/M3 # port que fa servir jupiter (necessari per Windows. En la meva màquina local no cal perquè suposo que ja està escoltant per aquest port) EXPOSE 8888 8888 # CMD jupyter notebook --no-browser --ip="0.0.0.0" --port=8888 --allow-root
arrencar_jupyter.sh
#/bin/bash jupyter notebook --no-browser --ip="0.0.0.0" --port=8888 --allow-root
xuleta
Esborrany
La imatge oficial: *https://hub.docker.com/r/pytorch/pytorch El Dockerfile oficial és a: * https://github.com/pytorch/pytorch/blob/main/Dockerfile PyTorch is a deep learning framework that puts Python first. It provides Tensors and Dynamic neural networks in Python with strong GPU acceleration. $ docker pull pytorch/pytorch Using default tag: latest latest: Pulling from pytorch/pytorch 7007490126ef: Pull complete f030756bea58: Pull complete 002e0840847c: Pull complete 4f4fb700ef54: Pull complete e991862a3134: Pull complete Digest: sha256:e4aaefef0c96318759160ff971b527ae61ee306a1204c5f6e907c4b45f05b8a3 Status: Downloaded newer image for pytorch/pytorch:latest docker.io/pytorch/pytorch:latest Són 3.4 GB $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE pytorch/pytorch latest 1bfcece93725 13 days ago 7.2GB * https://docs.docker.com/engine/reference/commandline/exec/ docker run --name pytorch2 -d -i -t pytorch/pytorch:latest /bin/sh 0afbc40cb085d96e99f241975ec4d6b030761bba348e183a6b4fc71b5c96b056 This creates and starts a container named pytorch2 from an alpine image with an sh shell as its main process. The -d option (shorthand for --detach) sets the container to run in the background, in detached mode, with a pseudo-TTY attached (-t). The -i option is set to keep STDIN attached (-i), which prevents the sh process from exiting immediately. $ docker ps -a $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0afbc40cb085 pytorch/pytorch:latest "/bin/sh" 19 seconds ago Up 18 seconds pytorch2 Next, execute a command on the container. $ docker exec -it pytorch2 /bin/bash root@0afbc40cb085:/workspace# <- ja sóc dins el docker This starts a new shell session in the container pytorch2 (compte! no confondre exec amb start) # python --version Python 3.10.13 # python >>> import torch >>> print(torch.__version__) 2.1.0 >>> x = torch.rand(5, 3) >>> print(x) tensor([[0.9976, 0.6759, 0.8950], [0.2835, 0.4624, 0.2493], [0.8311, 0.0133, 0.7116], [0.2142, 0.3823, 0.4454], [0.5836, 0.7235, 0.6720]]) >>> torch.cuda.is_available() False Per mirar les llibreries que tenim instal·lades: # pip list Package Version ----------------------- ------------ asttokens 2.0.5 astunparse 1.6.3 attrs 23.1.0 backcall 0.2.0 beautifulsoup4 4.12.2 boltons 23.0.0 brotlipy 0.7.0 certifi 2023.7.22 cffi 1.15.1 chardet 4.0.0 charset-normalizer 2.0.4 click 8.0.4 conda 23.9.0 conda-build 3.27.0 conda-content-trust 0.2.0 conda_index 0.3.0 conda-libmamba-solver 23.7.0 conda-package-handling 2.2.0 conda_package_streaming 0.9.0 cryptography 41.0.3 decorator 5.1.1 dnspython 2.4.2 exceptiongroup 1.0.4 executing 0.8.3 expecttest 0.1.6 filelock 3.9.0 fsspec 2023.9.2 gmpy2 2.1.2 hypothesis 6.87.2 idna 3.4 ipython 8.15.0 jedi 0.18.1 Jinja2 3.1.2 jsonpatch 1.32 jsonpointer 2.1 libarchive-c 2.9 libmambapy 1.4.1 MarkupSafe 2.1.1 matplotlib-inline 0.1.6 mkl-fft 1.3.8 mkl-random 1.2.4 mkl-service 2.4.0 more-itertools 8.12.0 mpmath 1.3.0 networkx 3.1 numpy 1.26.0 packaging 23.1 parso 0.8.3 pexpect 4.8.0 pickleshare 0.7.5 Pillow 10.0.1 pip 23.2.1 pkginfo 1.9.6 pluggy 1.0.0 prompt-toolkit 3.0.36 psutil 5.9.0 ptyprocess 0.7.0 pure-eval 0.2.2 pycosat 0.6.6 pycparser 2.21 Pygments 2.15.1 pyOpenSSL 23.2.0 PySocks 1.7.1 python-etcd 0.4.5 pytz 2023.3.post1 PyYAML 6.0 requests 2.31.0 ruamel.yaml 0.17.21 ruamel.yaml.clib 0.2.6 setuptools 68.0.0 six 1.16.0 sortedcontainers 2.4.0 soupsieve 2.5 stack-data 0.2.0 sympy 1.11.1 tomli 2.0.1 toolz 0.12.0 torch 2.1.0 torchaudio 2.1.0 torchelastic 0.2.2 torchvision 0.16.0 tqdm 4.65.0 traitlets 5.7.1 triton 2.1.0 truststore 0.8.0 types-dataclasses 0.6.6 typing_extensions 4.7.1 urllib3 1.26.16 wcwidth 0.2.5 wheel 0.41.2 zstandard 0.19.0 Sortim de la shell # exit $ Per aturar el docker: Per eliminar el docker: docker stop -d pytorch2 o bé: docker stop 0afbc40cb085 $ docker ps <- ja no apareix $ docker ps -a <- encara apareix docker rm pytorch2 o bé docker rm 0afbc40cb085 Però la imatge encara hi és: docker image ls Millor no confondre el nom de la imatge amb el nom del contenidor: $ docker run --name DOCKERIA -d -i -t docker-ia:latest /bin/sh Open a shell inside a running container: $ docker exec -it DOCKERIA /bin/bash Per saber les últimes versions dels paquets disponibles fem servir el cercador: *https://pypi.org/search Important, cada vegada que vull actualitzar el Dockerfile i tornar a fer el build, no cal eliminar la imatge. Faig el build i la imatge s'actualitza: Removing intermediate container 4370c5300b24 ---> f30e2cef329d Successfully built f30e2cef329d Successfully tagged docker-ia:latest La única cosa que fa és canviar el id =============================== I ara hauré de fer servir aquesta imatge oficial per 'construir' el docker IOC, amb la idea de fer un docker de l'assignatura Em puc guiar en: *https://wiki.joanillo.org/index.php/Docker:_PostgreSQL en el docker hi he de posar: -variables d'entorn -copiar fitxers -instal·lar nous paquets: editors de text, noves llibreries -com farem una carpeta compartida? 1. Creem una carpeta per al projecte 2. Creem el script Dockerfile 3. Fem el docker build: $ docker build -t docker-ia -f ./Dockerfile_1_0 . S'haurà creat un nou docker: $ docker image ls que el puc arrencar: $ docker run ... i executar: $ docker exec ... He d'anar versionant i documentant les versions del docker Això s'hauria de lligar amb un docker de jupyter, i arrencar-lo tots dos amb docker compose Anem a fer-ho: cd /home/joan/IOC/IC03_IA_BD/nous_materials/M3/M3U4/docker_ia el fitxer Dockerfile_1_0 de moment nomeés conté: FROM pytorch/pytorch $ docker build -t docker-ia -f ./Dockerfile_1_0 . <- per defecte el tag és latest Sending build context to Docker daemon 2.048kB Step 1/1 : FROM pytorch/pytorch ---> 1bfcece93725 Successfully built 1bfcece93725 Successfully tagged docker-ia:latest ho ha fet bé: $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE docker-ia latest 1bfcece93725 13 days ago 7.2GB pytorch/pytorch latest 1bfcece93725 13 days ago 7.2GB l'eliminem i millorem el script: docker rmi docker-ia:latest Amb shared folder a la ruta on estic treballant: $ docker run --user root --name DOCKERIA --mount type=bind,source="$(pwd)",target=/home/dockeria -d -i -t docker-ia:latest /bin/bash opció -d: detached -> arrenca però tinc el prompt de la màquina host. o i aleshores puc fer el exec sense opció -d: entro directament a la màquina El cicle de vida d'un docker seria: $ docker build ... -> crea la imatge ($ docker image ls) $ docker run ... -> crea i arrenca el docker (apareix a docker ps i docker ps -a) $ docker start DOCKERIA -> Per arrencar el docker (no cal si acabo de fer docker run). Apareix a docker ps $ docker exec -it DOCKERIA /bin/bash (Open a shell inside a running container) $ docker stop DOCKERIA -> per aturar el docker (no apareix a docker ps, sí que apareix a docker ps -a) $ docker start DOCKERIA -> si estava aturat, torno a arrencar-lo (després d'un stop no s'ha de fer run, s'ha de fer start) Per eliminar el docker: $ docker stop DOCKERIA (aturar-lo si estava arrencat, però de fet no cal) $ docker rm DOCKERIA (elimino el docker) (recordar que amb una imatge del docker puc crear vàries instàncies, varis contenidors. Però clar, han de tenir noms diferents: DOCKERIA1, DOCKERIA2) $ docker rmi docker-ia (elimino la imatge del docker) $ docker exec -it DOCKERIA /bin/bash Ara només em falta fer que arrenqui un servidor de jupyter $ docker run -dit -p 8888:8888 --user root --name DOCKERIA --mount type=bind,source="$(pwd)",target=/home/dockeria docker-ia:latest Finalment ja ho tinc: en el Dockerfile comento la línia de què arrenqui el jupyter automàticament. Ja ho faré manualment. dins del contenidor: # jupyter notebook i aleshores se m'obre un navegador local i ja puc fer funcionar el jupyter Si no vull que se m'obri el navegador automàticament, --no-browser Finalment: 1) Si no vull que arrenqui el jupyter notebook automàticament en el docker -en el Dockerfile s'ha de comentar la línia que fa referència a arrencar el jupyter -arrenco el docker $ docker run -dit -p 8888:8888 --user root --name DOCKERIA --mount type=bind,source="$(pwd)",target=/home/dockeria docker-ia:latest $ docker exec -it DOCKERIA /bin/bash dins del docker, arrenco el jupyter al port 8888: # jupyter notebook --ip="0.0.0.0" --port=8888 --allow-root & (amb el & recupero el prompt del sistema) -ja puc accedir amb el navegador, des de la màquina local, al Jupyter: * http://127.0.0.1:8888/?token=d4f4e7d2edce21c6725ccb35c2298d690dc0ed3858b7f23e 2) Si vull que arrenqui el jupyter notebook automàticament en el docker -En el Dockerfile habilito la línia: CMD jupyter notebook --no-browser --ip="0.0.0.0" --port=8888 --allow-root -s'ha de tornar a fer el build del docker: $ docker build -t docker-ia -f ./Dockerfile_1_0 . -faig el run (important, treure l'opció detached -d, i també treure el /bin/bash) $ docker run -it -p 8888:8888 --user root --name DOCKERIA --mount type=bind,source="$(pwd)",target=/home/dockeria docker-ia:latest To access the notebook, open this file in a browser: file:///root/.local/share/jupyter/runtime/nbserver-6-open.html Or copy and paste one of these URLs: http://d7a87ab15598:8888/?token=3c5470fbe737c91164d06203e93f7b4c9bffc2340dd29bd8 or http://127.0.0.1:8888/?token=3c5470fbe737c91164d06203e93f7b4c9bffc2340dd29bd8 Dels tres enllaços proposats, només funciona l'últim: http://127.0.0.1:8888/... La única cosa que he de fer és revisar el fitxer requirements, doncs he afegit llibreries mirant el requirements de PCD, que no sé si són obligatoris. -> efectivament, no calen tota la resta de llibreries i les comento. Ara tinc unes llibreries mínimes. Però el docker mare era de pytorch, i això ja anava amb una sèrie de llibreries. Per saber totes les llibreries que tinc instal·lades: # pip freeze asttokens @ file:///opt/conda/conda-bld/asttokens_1646925590279/work astunparse==1.6.3 attrs==23.1.0 backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work beautifulsoup4 @ file:///croot/beautifulsoup4-split_1681493039619/work bleach==6.1.0 boltons @ file:///croot/boltons_1677628692245/work brotlipy==0.7.0 certifi @ file:///croot/certifi_1690232220950/work/certifi cffi @ file:///croot/cffi_1670423208954/work chardet @ file:///home/builder/ci_310/chardet_1640804867535/work charset-normalizer @ file:///tmp/build/80754af9/charset-normalizer_1630003229654/work click @ file:///tmp/build/80754af9/click_1646056706450/work comm==0.1.4 conda @ file:///croot/conda_1696257509808/work conda-build @ file:///croot/conda-build_1696257509796/work conda-content-trust @ file:///croot/conda-content-trust_1693490622020/work conda-libmamba-solver @ file:///croot/conda-libmamba-solver_1691418897561/work/src conda-package-handling @ file:///croot/conda-package-handling_1690999929514/work conda_index @ file:///croot/conda-index_1695310357675/work conda_package_streaming @ file:///croot/conda-package-streaming_1690987966409/work contourpy==1.1.1 cryptography @ file:///croot/cryptography_1694444244250/work cycler==0.12.1 debugpy==1.8.0 decorator @ file:///opt/conda/conda-bld/decorator_1643638310831/work defusedxml==0.7.1 dnspython==2.4.2 exceptiongroup @ file:///croot/exceptiongroup_1668714342571/work executing @ file:///opt/conda/conda-bld/executing_1646925071911/work expecttest==0.1.6 fastjsonschema==2.18.1 filelock @ file:///croot/filelock_1672387128942/work fonttools==4.43.1 fsspec==2023.9.2 gmpy2 @ file:///tmp/build/80754af9/gmpy2_1645455533097/work hypothesis==6.87.2 idna @ file:///croot/idna_1666125576474/work ipykernel==6.25.2 ipython @ file:///croot/ipython_1694181358621/work ipython-genutils==0.2.0 ipywidgets==8.1.1 jedi @ file:///tmp/build/80754af9/jedi_1644315229345/work Jinja2 @ file:///croot/jinja2_1666908132255/work joblib==1.3.2 jsonpatch @ file:///tmp/build/80754af9/jsonpatch_1615747632069/work jsonpointer==2.1 jsonschema==4.19.1 jsonschema-specifications==2023.7.1 jupyter==1.0.0 jupyter-console==6.6.3 jupyter_client==8.4.0 jupyter_core==5.4.0 jupyterlab-pygments==0.2.2 jupyterlab-widgets==3.0.9 kiwisolver==1.4.5 libarchive-c @ file:///tmp/build/80754af9/python-libarchive-c_1617780486945/work libmambapy @ file:///croot/mamba-split_1685993156657/work/libmambapy MarkupSafe @ file:///opt/conda/conda-bld/markupsafe_1654597864307/work matplotlib==3.8.0 matplotlib-inline @ file:///opt/conda/conda-bld/matplotlib-inline_1662014470464/work mistune==3.0.2 mkl-fft @ file:///croot/mkl_fft_1695058164594/work mkl-random @ file:///croot/mkl_random_1695059800811/work mkl-service==2.4.0 more-itertools @ file:///tmp/build/80754af9/more-itertools_1637733554872/work mpmath @ file:///croot/mpmath_1690848262763/work nbclient==0.8.0 nbconvert==7.9.2 nbformat==5.9.2 nest-asyncio==1.5.8 networkx @ file:///croot/networkx_1690561992265/work notebook==6.0.0 numpy @ file:///croot/numpy_and_numpy_base_1695830428084/work/dist/numpy-1.26.0-cp310-cp310-linux_x86_64.whl#sha256=fc2732718bc9e06a7b702492cb4f5afffe9671083930452d894377bf563464a3 packaging @ file:///croot/packaging_1693575174725/work pandas==2.1.1 pandocfilters==1.5.0 parso @ file:///opt/conda/conda-bld/parso_1641458642106/work pexpect @ file:///tmp/build/80754af9/pexpect_1605563209008/work pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work Pillow @ file:///croot/pillow_1696580024257/work pkginfo @ file:///croot/pkginfo_1679431160147/work platformdirs==3.11.0 pluggy @ file:///tmp/build/80754af9/pluggy_1648024709248/work prometheus-client==0.17.1 prompt-toolkit @ file:///croot/prompt-toolkit_1672387306916/work psutil @ file:///opt/conda/conda-bld/psutil_1656431268089/work ptyprocess @ file:///tmp/build/80754af9/ptyprocess_1609355006118/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl pure-eval @ file:///opt/conda/conda-bld/pure_eval_1646925070566/work pycosat @ file:///croot/pycosat_1696536503704/work pycparser @ file:///tmp/build/80754af9/pycparser_1636541352034/work Pygments @ file:///croot/pygments_1684279966437/work pyOpenSSL @ file:///croot/pyopenssl_1690223430423/work pyparsing==3.1.1 PySocks @ file:///home/builder/ci_310/pysocks_1640793678128/work python-dateutil==2.8.2 python-etcd==0.4.5 pytz @ file:///croot/pytz_1695131579487/work PyYAML @ file:///croot/pyyaml_1670514731622/work pyzmq==25.1.1 qtconsole==5.4.4 QtPy==2.4.0 referencing==0.30.2 requests @ file:///croot/requests_1690400202158/work rpds-py==0.10.6 ruamel.yaml @ file:///croot/ruamel.yaml_1666304550667/work ruamel.yaml.clib @ file:///croot/ruamel.yaml.clib_1666302247304/work scikit-learn==1.3.1 scipy==1.11.3 seaborn==0.13.0 Send2Trash==1.8.2 six @ file:///tmp/build/80754af9/six_1644875935023/work sortedcontainers==2.4.0 soupsieve @ file:///croot/soupsieve_1696347547217/work stack-data @ file:///opt/conda/conda-bld/stack_data_1646927590127/work sympy @ file:///croot/sympy_1668202399572/work terminado==0.17.1 threadpoolctl==3.2.0 tinycss2==1.2.1 tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work toolz @ file:///croot/toolz_1667464077321/work torch==2.1.0 torchaudio==2.1.0 torchelastic==0.2.2 torchvision==0.16.0 tornado==6.3.3 tqdm @ file:///croot/tqdm_1679561862951/work traitlets @ file:///croot/traitlets_1671143879854/work triton==2.1.0 truststore @ file:///croot/truststore_1695244293384/work types-dataclasses==0.6.6 typing_extensions @ file:///croot/typing_extensions_1690297465030/work tzdata==2023.3 urllib3 @ file:///croot/urllib3_1686163155763/work wcwidth @ file:///Users/ktietz/demo/mc3/conda-bld/wcwidth_1629357192024/work webencodings==0.5.1 widgetsnbextension==4.0.9 zstandard @ file:///croot/zstandard_1677013143055/work =============================== Ara que ja tinc el docker en funcionament, fem un primer exemple: * https://pytorch.org/tutorials/beginner/blitz/neural_networks_tutorial.html # python pytorch_exemple.py Net( (conv1): Conv2d(1, 6, kernel_size=(5, 5), stride=(1, 1)) (conv2): Conv2d(6, 16, kernel_size=(5, 5), stride=(1, 1)) (fc1): Linear(in_features=400, out_features=120, bias=True) (fc2): Linear(in_features=120, out_features=84, bias=True) (fc3): Linear(in_features=84, out_features=10, bias=True) ) 10 torch.Size([6, 1, 5, 5]) tensor([[-0.0728, 0.0432, -0.0563, -0.0641, 0.0657, 0.0294, 0.0797, -0.0440, -0.0360, -0.0623]], grad_fn=<AddmmBackward0>) tensor(0.6838, grad_fn=<MseLossBackward0>) <MseLossBackward0 object at 0x7fe91e32a320> <AddmmBackward0 object at 0x7fe91e32a350> <AccumulateGrad object at 0x7fe91e32a350> conv1.bias.grad before backward None conv1.bias.grad after backward tensor([ 0.0098, 0.0066, -0.0145, 0.0090, -0.0029, -0.0041]) =============================== Publicar el docker a hub.docker.com Per tal de fer el push, primer m'he de logar a dockerhub, i després li he de canviar el tag al docker de manera que el prefix sigui el nom del login: joanillo/docker-ia:latest $ docker login username: joanillo password: ******** login succeeded $ docker tag docker-ia:latest joanillo/docker-ia:latest $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE joanillo/docker-ia latest 4294e7a59a0e 15 hours ago 7.63GB docker-ia latest 4294e7a59a0e 15 hours ago 7.63GB $ docker push joanillo/docker-ia:latest (són 7 GB que s'han de pujar) =============================== Utilitzar el docker docker-ia a una màquina Linux Concretament, en un futur proper, voldrem utilitzar aquest docker en una màquina IsardVDI Primer de tot, esborro tot el que tinc. I després ja m'ho descarrego del núvol: $ docker pull joanillo/docker-ia:latest $ docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE joanillo/docker-ia latest 4294e7a59a0e 17 hours ago 7.63GB $ docker run -dit -p 8888:8888 --user root --name DOCKERIA --mount type=bind,source="$(pwd)",target=/home/dockeria joanillo/docker-ia:latest $ docker exec -it DOCKERIA /bin/bash Efectivament hi ha un problema (mirar tornar a provar més avall), es fa bé la carpeta compartida. Però jo dins del contenidor esperava trobar tots els fitxers que vull que hi siguin de forma persistent. I efectivament no hi són. A més, crec que és una mala idea que el target de la carpeta compartida sigui /home/dockeria quan de fet aquest és el meu directori de treball. Hauria de ser diferent. # jupyter notebook --ip="0.0.0.0" --port=8888 --allow-root funciona NOTA: Efectivament, quan esborro una imatge amb -rmi s'allibera l'espai $ df -h S. fitxers Mida En ús Lliure %Ús Muntat a /dev/nvme0n1p2 457G 359G 76G 83% / S. fitxers Mida En ús Lliure %Ús Muntat a /dev/nvme0n1p2 457G 352G 83G 81% / S'han alliberat els 7GB que ocupa aquest docker Per veure els volums que tinc: $ docker volume ls DRIVER VOLUME NAME local 0ed16bb5ffd6f6f3baa2723f57aeb6e31631aba4c4ff1f423908ff632d3e00c2 local 02e3e3de061260e1adbdd5e12f87390847172d4806aa0beaf5dbe4e4ab28fbb7 local 3acac6f82ea7be5ca01c72c7ae31c1466e6aeb32c74928acd93d3c03653235b8 local 4a89015c48e7934f2a30c0c1257a1f2a82a09b97db3dfca01ed20a161d6356c9 ... Aquests volums puc veure què hi ha dins a: /var/lib/docker/volumes/ per ex: cd /var/lib/docker/volumes/02e3e3de061260e1adbdd5e12f87390847172d4806aa0beaf5dbe4e4ab28fbb7/_data $ sudo su (important fer-ho com a root) # docker volume inspect e1186c681e8581f76aa90ba49b8b09bf1534a06a6497b0759f9f3127add1e635 [ { "CreatedAt": "2021-11-05T22:41:43+01:00", "Driver": "local", "Labels": null, "Mountpoint": "/var/lib/docker/volumes/e1186c681e8581f76aa90ba49b8b09bf1534a06a6497b0759f9f3127add1e635/_data", "Name": "e1186c681e8581f76aa90ba49b8b09bf1534a06a6497b0759f9f3127add1e635", "Options": null, "Scope": "local" } ] però encara no veig aquest volum a quina Image Id es correspon $ docker build -t docker-ia -f ./Dockerfile_1_0 . $ cd prova -> vull que la carpeta compartida sigui prova, i fixem-nos que el punt de muntatge és source="$(pwd)". Per tant, a shared_folder dins del docker hi haurà la carpeta des de la qual executem la comanda docker run: $ docker run -dit -p 8888:8888 --user root --name DOCKERIA --mount type=bind,source="$(pwd)",target=/home/dockeria/shared_folder docker-ia:latest 02ee773b6903264f486b6de5fd577dcef60b0e9a144c1811e7ef24ac3b4a460c docker exec -it DOCKERIA /bin/bash root@4f316ddd7aa8:/home/dockeria/M3# Correcte: dins de M3 hi ha la carpeta data/, i al mateix nivell que M3/ hi ha la carpeta shared_folder/ La idea és que sigui un docker que pugui servir per diversos mòduls, i per tant no s'ha de donar preferència a M3. S'executa correctament el test de pytorch que està dins la carpeta test. Tornem a provar (17:15): $ docker push joanillo/docker-ia:latest esborro tot el que tinc en local $ docker pull joanillo/docker-ia:latest =============================== Utilitzar el docker docker-ia a una màquina Windows En una màquina Windows utilitzem el Docker Desktop, que ha d'estar arrencat En la línia de comandes de Windows: $ docker pull joanillo/docker-ia:latest I ara ja m'apareix en el Docker Desktop Sobre el contenidor, Run, i selecciono CLI (command line interface, que és la consola) Ha funcionat bastant bé: Quan faig el run, he d'anar a optional settings -carpeta compartida: selecciono el meu directori de treball de windows, i selecciono al doker /home/dockeria. La compartició de carpetes es fa bé. -ara bé, jo esperava trobar a /home/dockeria la carpeta /data i d'altres, i no hi ha res (solucionar-ho) -diu que 'no ports exposed in this image'. I per tant no podré obrir el jupyter Ara bé, jo hauria de poder fer un docker run igual que faig a Linux, no? Més tard: 18.04 Ja funciona tot perfecte: En el Dockerfile he posat el EXPOSE 8888 8888 -funciona el shared_folder -tinc les carpetes data/ i test/ -funciona l'exemple pytorch -funciona el jupyter notebook ================================= TODO: Arrencar el jupyter notebook és un rotllo. S'ha de posar: $ jupyter notebook --no-browser --ip="0.0.0.0" --port=8888 --allow-root Per solucionar-ho és tan fàcil com fer el script arrencar_jupyter.sh #/bin/bash jupyter notebook --no-browser --ip="0.0.0.0" --port=8888 --allow-root chmod a+x arrencar_jupyter.sh ./arrencar_jupyter.sh però clar, això no ho he de fer manualment, sinó que ha d'estar dins del Dockerfile TODO: posar-ho tot a un IsardVDI
creat per Joan Quintana Compte, octubre 2023