Difference between revisions of "Containers cheat sheet"
Jump to navigation
Jump to search
hpcwiki>Dvory |
m (1 revision imported) |
(No difference)
|
Latest revision as of 11:38, 14 May 2023
action | docker | singularity |
---|---|---|
pull existing image from docker hub | docker pull ubuntu:18.04 |
sudo singularity build ubuntu_18.04.simg docker://ubuntu:18.04 |
login to container shell | docker run -it ubuntu:18.04 bash |
singularity shell ubuntu_18.04.simg |
update image NOT using a file | Login to container shell:
docker run -it ubuntu:18.04 bash apt update apt install vim exit Commit the changes while the container is down: Locate Container ID:docker ps -aCommit the changes to a new image tag: docker commit 19b0acbfef1b ubuntu:18.04_tau |
Create writable image:sudo singularity build --sandbox ubuntu_18.04_tau.simg docker://ubuntu:18.04Login to image shell in a writable mode: sudo singularity shell --writable ubuntu_18.04_tau.simg apt update apt install vim exit |
create new image | 1. Edit Dockerfile (file name must be Dockerfile):
#Download base image FROM ubuntu:18.04 # Update vim RUN apt update && apt install -y vim # Define environment variable ENV TEAM HPC 2. Build image: docker build -t ubuntu:18.04_tau2 . |
1. Edit Singularity file (file name can be anything): #Download base image Bootstrap: docker FROM: ubuntu:18.04 # Update vim %post apt-get update apt-get install -y vim %environment TEAM=HPC export TEAM 2. Build image: sudo singularity build ubuntu_18.04_tau2.simg Singfile |
run as a daemon | Run image as daemon using infinite sleep:
docker run -d ubuntu:18.04_tau2 sleep 999999999 |
|
list running containers | docker ps |
|
list running and stopped containers | docker ps -a |
|
list local images | docker images |
ls |
Start a downed container (note it must have already been executed at least once) | docker start c4f7efb53d1a |
|
Stop a container | docker stop c4f7efb53d1a |
|
Delete a container | docker rm 3271c613e00a |
|
Delete an image | docker rmi 9f38484d220f |
rm ubuntu_18.04_tau2.simg |
view container logs | docker logs f28eb1af539d |
|
view disk usage | docker system df |
|
view full details about the docker service | docker info |
|
view full details about a container | docker inspect containerid |
|
start shell inside daemonized container |
docker exec -it f28eb1af539d bash To exit: <CTL>+p, <CTL>+q (typing 'exit' will kill the container) |
|
Run program from within the image without parameters | docker run -it ubuntu:18.04_tau4 python |
Add to the Singularity file:
%apprun python exec python ""${@}"" Build the singularity image: sudo singularity build ubuntu_18.04_tau2.simg Singfile Run the program: singularity run --app python ubuntu_18.04_tau4.simg |
Run program from within the image with parameters | docker run -it ubuntu:18.04_tau4 python -c "print('hello world')" |
Add to the Singularity file:
%apprun python exec python "${@}"Build the singularity image: sudo singularity build ubuntu_18.04_tau2.simg SingfileRun the program: singularity run --app python ubuntu_18.04_tau4.simg -c "print('hello world')" |
Add help to image | Add to the Singularity file:
%help Python version 2.7.15rc1 Usage ===== View help: $ singularity help ubuntu_18.04_tau4.simg Run Python from the container: $ singularity run --app python ubuntu_18.04_tau4.simgBuild the singularity image: sudo singularity build ubuntu_18.04_tau2.simg SingfileView the help: singularity help ubuntu_18.04_tau4.simg |