In AWS, created a docker image with a python script to print a string(basicprint.py
)
docker file:
FROM python
COPY ./basicprint.py ./
CMD ["python", "basicprint.py"]
It works fine then saved docker image as .tgz
file.
copy that .tgz
file in to my local.
I converted docker image(.tgz
) into singularity
image by using
singularity build sing_image.sif docker-archive://filename.tgz
it was successfully created sing_image.sif
singularity run sing_image.sif
It throws an error : basicprint.py: No such file or directory
Any suggestions on correct method of conversion without missing the file.
Note that you put your file under the very root. singularity
removed your file during conversion and cleaning. Similar issues have been reported and are, in general, expected when working with containers.
This slightly modified image
FROM python:3.11-slim
COPY ./basicprint.py ./
CMD ["ls"]
demonstrates that the file lands under the linux root:
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ docker build . --tag test-sing
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ docker run -it test-sing
root@ed8e3545a00b:/# ls
basicprint.py bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
Now, let me demonstrate the working version. Importantly, follow best Docker practices and use the working dir
# Dockerfile
FROM python:3.11-slim-bullseye
RUN mkdir -p /usr/src
WORKDIR /usr/src
COPY ./basicprint.py /usr/src/
CMD ["python", "/usr/src/basicprint.py"]
where the sample Python script is
# basicprint.py
print('Welcome to my Docker!')
Then I build and test on Debian GNU/Linux 10
with Docker 20.10.17
and Singularity 3.11
:
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ singularity --version
singularity-ce version 3.11.0+277-gcd6fa5c0d
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ sudo docker build . --tag test-sing:latest
Successfully tagged test-sing:latest
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ docker save test-sing:latest --output test-sing.tgz
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ sudo singularity build test-sing.sif docker-archive:test-sing.tgz
...
INFO: Build complete: test-sing.sif
(base) maciej.skorski@kaggle-cpu-maciej:~/docker-debug$ sudo singularity run test-sing.sif
Welcome to my Docker!
Under the same software, I reproduced your error. So I think it has been solved! If you need any further assistance, we can set up a shared Virtual Machine with GitHub Codespace to make it fully reproducible.