Difference between revisions of "Deploy a container using Singularity"

From ScientificComputing
Jump to: navigation, search
Line 111: Line 111:
 
  >>>  
 
  >>>  
 
  Singularity> exit
 
  Singularity> exit
  [nethzusername@eu-ms-001-02 nethzusername]$
+
 
 +
As you can see that the container contains GCC 9.3.0 with Python 3.8.5 and TensorFlow 2.5.0. At the time of writing tutorial, the latest version of GCC is 8.2.0 and TensorFlow 2.4.0
 +
 
 +
  [nethzusername@eu-ms-001-02 nethzusername]$ module avail gcc
 +
--------------------------- /cluster/apps/lmodules/Core --------------------------------
 +
  gcc/4.8.2    gcc/4.8.5 (L)    gcc/5.4.0    gcc/6.3.0    gcc/7.3.0    gcc/8.2.0 (D)
 +
 
 +
[nethzusername@eu-ms-001-02 nethzusername]$ module load gcc/6.3.0 python/3.8.5
 +
[nethzusername@eu-ms-001-02 nethzusername]$ python
 +
Python 3.8.5 (default, Oct  6 2020, 10:04:29)
 +
[GCC 6.3.0] on linux
 +
Type "help", "copyright", "credits" or "license" for more information.
 +
>>> import tensorflow as tf
 +
2021-06-09 14:56:47.778183: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library  'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /cluster/apps/gcc-6.3.0/openblas-0.2.20-cot3cawsqf4pkxjwzjexaykbwn2ch3ii/lib:/cluster/apps/nss/gcc-6.3.0/python/3.8.5/x86_64/lib64:/cluster/spack/apps/linux-centos7-x86_64/gcc-4.8.5/gcc-6.3.0-sqhtfh32p5gerbkvi5hih7cfvcpmewvj/lib64:/cluster/spack/apps/linux-centos7-x86_64/gcc-4.8.5/gcc-6.3.0-sqhtfh32p5gerbkvi5hih7cfvcpmewvj/lib:/cluster/apps/lsf/10.1/linux2.6-glibc2.3-x86_64/lib
 +
2021-06-09 14:56:47.778214: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not  have a GPU set up on your machine.
 +
>>> tf.__version__
 +
'2.4.0'
 +
>>>
 +
 
  
 
{{back_to_tutorials}}
 
{{back_to_tutorials}}

Revision as of 13:58, 9 June 2021

< Examples

Create a Docker file and build a docker image on your local computer

$ mkdir test_container
$ cd test_container
  • Open file named **Dockerfile** with a text editor
FROM ubuntu:latest

WORKDIR /home/project

RUN apt-get -y update
RUN apt-get install -y lsb-release python3 python3-pip \
&& pip install numpy==1.19 matplotlib tensorflow
  • Build an image
$ docker build -t username/ubuntu-python3:latest .
Sending build context to Docker daemon  3.072kB
Step 1/4 : FROM ubuntu:latest
 ---> 7e0aa2d69a15
Step 2/4 : WORKDIR /home/project
 ---> Using cache
 ---> d9947182f6a8
Step 3/4 : RUN apt-get -y update
 ---> Using cache
 ---> 89a634ac491b
Step 4/4 : RUN apt-get install -y lsb-release python3 python3-pip && pip install numpy==1.19 matplotlib tensorflow
 ---> Using cache
 ---> d639b6f22ee5
Successfully built d639b6f22ee5
Successfully tagged username/ubuntu-python3:latest
$ docker images
 REPOSITORY                 TAG       IMAGE ID       CREATED          SIZE
 username/ubuntu-python3     latest    d639b6f22ee5   18 minutes ago   2.19GB

Deploy the image on the cluster

Use the Docker image on Dockerhub

  • Push the image to Dockerhub
$  docker push username/ubuntu-python3:latest
The push refers to repository [docker.io/username/ubuntu-python3]
4648e930d81f: Pushed 
2e38cc729d73: Pushed 
f281ab5d2fac: Pushed 
2f140462f3bc: Mounted from library/ubuntu 
63c99163f472: Mounted from library/ubuntu 
ccdbb80308cc: Mounted from library/ubuntu 
latest: digest: sha256:cd8a34b30aabe432232787d1e93844cd01027c2b235fb88f106297ed26c1f2ca size: 1576
  • Log into Euler
$ ssh nethzusername@euler.ethz.ch
  • Request a compute node with Singularity
$ bsub -n 1 -R singularity -R light -Is bash
Generic job.
Job <174809810> is submitted to queue <light.5d>.
<<Waiting for dispatch ...>>
<<Starting on eu-ms-001-02>>
[nethzusername@eu-ms-001-02 ~]$
  • Pull the Docker image with Singularity
[nethzusername@eu-ms-001-02 ~]$ cd $SCRATCH
[nethzusername@eu-ms-001-02 nethzusername]$ singularity pull docker://username/ubuntu-python3
INFO:    Converting OCI blobs to SIF format
WARNING: 'nodev' mount option set on /scratch, it could be a source of failure during build process
INFO:    Starting build...
Getting image source signatures
Copying blob 345e3491a907 done  
Copying blob 57671312ef6f done  
Copying blob 5e9250ddb7d0 done  
Copying blob 59cb202cc95d done  
Copying blob 11a3e9d5c98b done  
Copying blob 0dc45453c4be done  
Copying config 60390c52c7 done  
Writing manifest to image destination
Storing signatures
2021/06/09 14:05:31  info unpack layer: sha256:345e3491a907bb7c6f1bdddcf4a94284b8b6ddd77eb7d93f09432b17b20f2bbe
2021/06/09 14:05:32  info unpack layer: sha256:57671312ef6fdbecf340e5fed0fb0863350cd806c92b1fdd7978adbd02afc5c3
2021/06/09 14:05:32  info unpack layer: sha256:5e9250ddb7d0fa6d13302c7c3e6a0aa40390e42424caed1e5289077ee4054709
2021/06/09 14:05:32  info unpack layer: sha256:59cb202cc95d3e96a8ea195395e5aba5386cb0a7aefc920e419fa1b8b5b15bbf
2021/06/09 14:05:32  info unpack layer: sha256:11a3e9d5c98bcb1bc09f415abb9db936988faf1128fabe875ee18f31d497a9d2
2021/06/09 14:05:32  info unpack layer: sha256:0dc45453c4bed490c08acc9437d253d2c36290e72d00c43fa1779f7a42b12e48
INFO:    Creating SIF file...
[nethzusername@eu-ms-001-02 nethzusername]$ ll
ubuntu-python3_latest.sif
  • Run the container as shell
[nethzusername@eu-ms-001-02 nethzusername]$ singularity shell ubuntu-python3_latest.sif
Singularity> lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
Singularity> python3
Python 3.8.5 (default, May 27 2021, 13:30:53) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2021-06-09 14:08:24.919069: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library  'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /.singularity.d/libs
2021-06-09 14:08:24.919094: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not  have a GPU set up on your machine.
>>> tf.__version__
'2.5.0'
>>> 
Singularity> exit

As you can see that the container contains GCC 9.3.0 with Python 3.8.5 and TensorFlow 2.5.0. At the time of writing tutorial, the latest version of GCC is 8.2.0 and TensorFlow 2.4.0

[nethzusername@eu-ms-001-02 nethzusername]$ module avail gcc
--------------------------- /cluster/apps/lmodules/Core --------------------------------
  gcc/4.8.2    gcc/4.8.5 (L)    gcc/5.4.0    gcc/6.3.0    gcc/7.3.0    gcc/8.2.0 (D)
[nethzusername@eu-ms-001-02 nethzusername]$ module load gcc/6.3.0 python/3.8.5
[nethzusername@eu-ms-001-02 nethzusername]$ python
Python 3.8.5 (default, Oct  6 2020, 10:04:29) 
[GCC 6.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2021-06-09 14:56:47.778183: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library  'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /cluster/apps/gcc-6.3.0/openblas-0.2.20-cot3cawsqf4pkxjwzjexaykbwn2ch3ii/lib:/cluster/apps/nss/gcc-6.3.0/python/3.8.5/x86_64/lib64:/cluster/spack/apps/linux-centos7-x86_64/gcc-4.8.5/gcc-6.3.0-sqhtfh32p5gerbkvi5hih7cfvcpmewvj/lib64:/cluster/spack/apps/linux-centos7-x86_64/gcc-4.8.5/gcc-6.3.0-sqhtfh32p5gerbkvi5hih7cfvcpmewvj/lib:/cluster/apps/lsf/10.1/linux2.6-glibc2.3-x86_64/lib
2021-06-09 14:56:47.778214: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not  have a GPU set up on your machine.
>>> tf.__version__
'2.4.0'
>>> 


< Examples