Some notes from a recent tinkering with containerd and ctr ...
which ctr
/usr/bin/ctr
ctr version
Version: 1.4.4-0ubuntu1~20.04.2
Revision:
Go version: go1.13.8
Server:
Version: 1.4.4-0ubuntu1~20.04.2
Revision:
UUID: 47a84416-93a1-4934-b850-fecb8dddf519
Pull an image
ctr image pull docker.io/library/nginx:latest -u davidhay1969
index-sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750: exists |++++++++++++++++++++++++++++++++++++++|
manifest-sha256:61191087790c31e43eb37caa10de1135b002f10c09fdda7fa8a5989db74033aa: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:351ad75a6cfabc7f2e103963945ff803d818f0bdcf604fd2072a0eefd6674bde: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:596b1d696923618bec6ff5376cc9aed03a3724bc75b6c03221fd877b62046d05: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:30afc0b18f67ae8441c2d26e356693009bb8927ab7e3bce05d5ed99531c9c1d4: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:febe5bd23e98102ed5ff64b8f5987f516a945745c08bbcf2c61a50fb6e7b2257: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:8283eee92e2f756bd57f96ea295e332ab9031724267d4f939de1f7d19fe9611a: exists |++++++++++++++++++++++++++++++++++++++|
config-sha256:d1a364dc548d5357f0da3268c888e1971bbdb957ee3f028fe7194f1d61c6fdee: exists |++++++++++++++++++++++++++++++++++++++|
layer-sha256:69692152171afee1fd341febc390747cfca2ff302f2881d8b394e786af605696: exists |++++++++++++++++++++++++++++++++++++++|
elapsed: 1.3 s total: 0.0 B (0.0 B/s)
unpacking linux/amd64 sha256:6d75c99af15565a301e48297fa2d121e15d80ad526f8369c526324f0f7ccb750...
done
List images
ctr image list
Create a container ( in background mode via -d )
ctr run --net-host -d --rm -t docker.io/library/nginx:latest nginx
Nothing returned
List running containers
ctr container list
nginx docker.io/library/nginx:latest io.containerd.runc.v2
List tasks
ctr task list
nginx 1287661 RUNNING
List Linux processes
ps aux | grep containerd | grep -v grep
root 1287636 0.0 0.1 111852 7952 ? Sl 01:44 0:00 /usr/bin/containerd-shim-runc-v2 -namespace default -id nginx -address /run/containerd/containerd.sock
Inspect task
ctr task ps nginx
1287661 -
1287712 -
1287713 -
Attempt to remove task
ctr task delete nginx
ctr: task must be stopped before deletion: running: failed precondition
Attempt to remove container
ctr container delete nginx
ctr: cannot delete a non stopped container: {running 0 0001-01-01 00:00:00 +0000 UTC}
Kill the task
ctr task kill nginx
Nothing returned
Attempt to remove task
ctr task delete nginx
Nothing returned
Attempt to remove container
ctr container delete nginx
Nothing returned
Create a container ( in foreground mode via -t with bash )
- note that the container automatically terminates, and is removed, upon exit, via the --rm remove switch
ctr run --net-host -t --rm -t docker.io/library/nginx:latest nginx sh
Inspect Nginx configuration ( inside container )
cat /etc/nginx/nginx.conf
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
Exit container
exit
Create a container ( in foreground mode via -t with bash mounting a local /k8s directory into the container as /k8s )
mkdir /k8s
echo "Hello World!" >> /k8s/greeting.txt
ctr run --net-host --mount type=bind,src=/k8s,dst=/k8s,options=rbind -t --rm -t docker.io/library/nginx:latest nginx sh
#
Display greeting from inside container
cat /k8s/greeting.txt
Exit container
exit
No comments:
Post a Comment