The purpose of this page is to supplement Apptainer documentation.
Apptainer definition files (Definition Files — Apptainer User Guide 1.0 documentation):
Ex:
Bootstrap: docker From: python:3.9 %files /sdf/home/p/pnispero/BuildSystem/socket_server.py / %labels Author pnispero Version v0.0.1 %help This is a demo container used to illustrate a def file that uses all supported sections. %post apt update echo "Hello from inside the container" %runscript echo "Container was created $NOW" echo "Arguments received: $*" echo "Running socket_server.py" python3 /socket_server.py exec echo "$@" |
I created a basic server using Golang
// socket-server project main.go |
I created a definition file for it
Bootstrap: docker %files %labels %help %post %runscript |
I also made a simple client in python
import socket
client_socket = socket.socket() # instantiate message = input(" -> ") # take input while message.lower().strip() != 'bye': print('Received from server: ' + data) # show in terminal message = input(" -> ") # again take input client_socket.close() # close the connection
|
So, I created the image (Fun fact you can build without a go compiler because the compiler is taken from docker hub thats specified in the second step .def file)
(goenv) [pnispero@sdfiana002 container_test]$ apptainer build socket_server.sif socket_server.def |
Start the container
(goenv) [pnispero@sdfiana002 container_test]$ apptainer instance start socket_server.sif socket_server1 |
Check that the container is alive
(goenv) [pnispero@sdfiana002 container_test]$ apptainer instance list |
Run the runscript of the container
(goenv) [pnispero@sdfiana002 container_test]$ apptainer run instance://socket_server1 |
Screenshot of steps 5-7 (ignore the error)
Run the client
(goenv) [pnispero@sdfiana001 container_test]$ python3 socket_client.py |
Screenshot
Then once done, kill the container (note - If you ctrl+c the socket_server it will exit the go program, but the container will still run)
(goenv) [pnispero@sdfiana002 container_test]$ apptainer instance stop socket_server1 |