CentOS Stream 9
Sponsored Link

TensorFlow : Install Docker Image (CPU)2022/08/10

 
Install TensorFlow which is the Machine Learning Library.
On this example, Install TensorFlow official Docker Image without GPU support and run it on Containers.
[1]
[2] Install TensorFlow Docker (CPU only).
# pull TensorFlow image

[cent@dlp ~]$
podman pull docker.io/tensorflow/tensorflow:latest
[cent@dlp ~]$
podman images

REPOSITORY                       TAG         IMAGE ID      CREATED       SIZE
docker.io/tensorflow/tensorflow  latest      976c17ec6daa  36 hours ago  1.48 GB

# run container

[cent@dlp ~]$
podman run --rm docker.io/tensorflow/tensorflow:latest \
python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

2022-09-08 07:38:22.779379: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-09-08 07:38:24.244232: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
tf.Tensor(-483.35004, shape=(), dtype=float32)

# create Hello World test script and run it on container

[cent@dlp ~]$
vi hello_tensorflow.py
import tensorflow as tf
hello = tf.constant('Hello, TensorFlow World!')
tf.print(hello)

[cent@dlp ~]$
podman run --rm -v $PWD:/tmp -w /tmp docker.io/tensorflow/tensorflow:latest python3 ./hello_tensorflow.py

2022-09-08 07:40:32.431019: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
2022-09-08 07:40:34.001372: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
Hello, TensorFlow World!
[3] If SELinux is enabled, change pilicy.
[root@dlp ~]#
vi my-python.te
# create new

module my-python 1.0;

require {
        type user_home_t;
        type container_t;
        type user_home_dir_t;
        class file { create ioctl open read unlink write };
        class dir { add_name remove_name write };
}

#============= container_t ==============
allow container_t user_home_dir_t:dir { add_name remove_name write };
allow container_t user_home_dir_t:file { create ioctl open read unlink write };
allow container_t user_home_t:file { ioctl open read };

[root@dlp ~]#
checkmodule -m -M -o my-python.mod my-python.te

[root@dlp ~]#
semodule_package --outfile my-python.pp --module my-python.mod

[root@dlp ~]#
semodule -i my-python.pp

[4] Install TensorFlow Docker Image with Jupyter Notebook.
[cent@dlp ~]$
podman pull docker.io/tensorflow/tensorflow:latest-jupyter
[cent@dlp ~]$
podman images

REPOSITORY                       TAG             IMAGE ID      CREATED       SIZE
docker.io/tensorflow/tensorflow  latest-jupyter  c94342dbd1e8  36 hours ago  1.72 GB
docker.io/tensorflow/tensorflow  latest          976c17ec6daa  36 hours ago  1.48 GB

# run container as daemon

[cent@dlp ~]$
podman run -dt -p 8888:8888 docker.io/tensorflow/tensorflow:latest-jupyter

1aee64df6f7f75dd2afbdf7cce77e05315e31435c1ebc14f31c1258799347ad8

[cent@dlp ~]$
podman ps

CONTAINER ID  IMAGE                                           COMMAND               CREATED         STATUS             PORTS                   NAMES
1aee64df6f7f  docker.io/tensorflow/tensorflow:latest-jupyter  bash -c source /e...  23 seconds ago  Up 23 seconds ago  0.0.0.0:8888->8888/tcp  gallant_mahavira

# confirm URL

[cent@dlp ~]$
podman exec 1aee64df6f7f bash -c "jupyter notebook list"

Currently running servers:
http://0.0.0.0:8888/?token=5d4929bd5b94509d010c54540427fd6ac2b9a89565461668 :: /tf
  Access to the URL above, then it's possible to use Jupyter Notebook.
Matched Content