Setelah sekian lama ingin mencoba docker, kali ini saya benar-benar mencobanya. Selama ini saya bisa menghindari docker karena venv dan conda tidak pernah gagal. Karena kali ini conda gagal mendukung GPU di tensorflow 1.15, maka mau tidak mau Docker menjadi solusi terbaik.
Docker Untuk Menginstall Software (Paket/Library) Baru
# asumsi docker sudah terinstall $ docker run -it ubuntu bash # jika ada masalah permission, lakukan: sudo chmod 666 /var/run/docker.sock $ apt update $ apt install python3 $ apt install python3-pip $ python3 -m pip install opensmile $ apt install libsndfile1 libsndfile1-dev $ apt install sox $ apt insalll ffmpeg root@6e7dd3cbfee1:/# python3 Python 3.8.10 (default, Mar 15 2022, 12:22:08) [GCC 9.4.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import opensmile >>> opensmile.__version__ '2.4.1' >>> exit() root@6e7dd3cbfee1:/# ldd --version ldd ldd (Ubuntu GLIBC 2.31-0ubuntu9.7) 2.31 Copyright (C) 2020 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.
Menyimpan file docker dengan commit
Docker tidak didesain untuk menyimpan file, untuk menyimpan file (dan perubahan/update) dari docker yang sedang berjalan dan docker-docker sebelumnya gunakan perintah commit berikut.Format:
docker commit CONTAINER_ID IMAGE
$ docker ps -a # bisa juga dengan ps -l untuk docker yang sedang berjalan $ dokcer commit ef7d7090e3c7 ubuntu:opensmile
Docker Untuk Menginstall Software Lama (Tensorflow 1.15 dengan GPU support)
Solusi:
# asumsi docker belum terinstall $ sudo apt install docker.io $ curl https://get.docker.com #install curl jika belum ada $ sudo systemctl --now enable docker $ distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \ && curl -s -L https://nvidia.github.io/libnvidia-container/gpgkey | sudo apt-key add - \ && curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list $ sudo apt update $ docker images # list images docker REPOSITORY TAG IMAGE ID CREATED SIZE nvcr.io/nvidia/tensorflow 22.04-tf1-py3 8b2abbd886f0 2 years ago 9.51GB $ docker run --gpus all -it --rm nvcr.io/nvidia/tensorflow:22.04-tf1-py3 $ git clone https://github.com/houssamzenati/Efficient-GAN-Anomaly-Detection.git $ cd Efficient-GAN-Anomaly-Detection $ python3 main.py gan mnist run --nb_epochs=10 --label=0 ______ _____ _____ ____ |_ `.|_ _| / ___ `. .' '. | | `. \ | | |_/___) | | .--. | | | | | | | _ .'____.' | | | | _| |_.' /_| |__/ | / /_____ _| `--' | |______.'|________| |_______|(_)'.____.' [09:48:37 INFO @AnomalyDetection] Running script at gan.run_mnist 2022-03-30 09:48:37.916727: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudart.so.11.0 [09:48:37 WARNING @tensorflow] Deprecation warnings have been disabled. Set TF_ENABLE_DEPRECATION_WARNINGS=1 to re-enable them. [09:48:38 WARNING @tensorflow] From /TA/demo/Efficient-GAN-Anomaly-Detection/gan/run_mnist.py:4: The name tf.ConfigProto is deprecated. Please use tf.com pat.v1.ConfigProto instead. ... 2022-03-30 09:48:44.229713: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11 2022-03-30 09:48:44.683684: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8 [09:48:51 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 0 | time = 7s | loss gen = 0.7218 | loss dis = 1.3530 [09:48:54 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 1 | time = 3s | loss gen = 0.7747 | loss dis = 1.2383 [09:48:57 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 2 | time = 3s | loss gen = 0.8793 | loss dis = 1.0877 [09:49:01 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 3 | time = 3s | loss gen = 1.0170 | loss dis = 0.9235 [09:49:04 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 4 | time = 3s | loss gen = 1.1724 | loss dis = 0.7746 [09:49:07 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 5 | time = 3s | loss gen = 1.3378 | loss dis = 0.6493 [09:49:11 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 6 | time = 3s | loss gen = 1.5056 | loss dis = 0.5522 [09:49:14 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 7 | time = 3s | loss gen = 1.6597 | loss dis = 0.4744 [09:49:17 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 8 | time = 3s | loss gen = 1.7992 | loss dis = 0.4116 [09:49:21 INFO @GAN.train.mnist.fm.0] Epoch terminated Epoch 9 | time = 3s | loss gen = 1.8616 | loss dis = 0.3848 [09:49:21 WARNING @GAN.train.mnist.fm.0] Testing evaluation... [09:54:19 INFO @GAN.train.mnist.fm.0] Testing : mean inference time is 1.5292 Testing | PRC AUC = 0.7183
Me-mount direktori
Skenario: Mengedit file diluar docker, mengeksekusi file (misal python) didalam docker. Caranya adalah sebagai berikut.
$ docker run --gpus all -it --mount type=bind,source=/TA,target=/TA tf1.15:py3Dimana `source` adalah sumber direktori, dan `target` adalah target direktori. Image docker sebelumnya sudah saya commit menjadi `tf1.15` dengan tag `py3`.
Menambahkan docker ke sudoers
Ketika membuka docker, terlihat bahwa tanda di baris kiri terminal adalah sharp #, ini menandakan kita masuk sebagai super user (sudo). Karenanya ada error saat membuka docker pertama kali (harus chmod 666 dulu). Solusi ini hanya berjalan sementara, untuk solusi permanen kita bisa menambahkan docker ke grup sudoers sebagai berikut.# menambahkan grup baru bernama docker $ sudo groupadd docker # menambahkan $USER ke grup docker $ sudo usermod -aG docker $USER # merefresh grup $ newgrp docker