From bc69788d79e9527cfbbaa7baa788255bef4d2f12 Mon Sep 17 00:00:00 2001 From: yukang Date: Wed, 25 Aug 2021 13:59:21 +0000 Subject: [PATCH 1/3] fix tutorial in readme --- .gitignore | 4 ++++ README.md | 49 +++++++++++++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index 2713058a2..27ec3d616 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ youki /tutorial +/rootfs + .idea/ **/target @@ -9,4 +11,6 @@ youki tags tags.lock tags.temp +/config.json + diff --git a/README.md b/README.md index 417cec791..d959ede19 100644 --- a/README.md +++ b/README.md @@ -90,32 +90,52 @@ $ ./youki -h # you can get information about youki command ## Tutorial -Let's try to run a container that executes `sleep 5` using youki. -Maybe this tutorial is need permission as root. +Let's try to run a container that executes `sleep 30` with youki. This tutorial may need root permission. ```sh $ git clone git@github.com:containers/youki.git $ cd youki $ ./build.sh -$ mkdir tutorial -$ cd tutorial + $ mkdir rootfs + +# use docker to export busybox into the rootfs directory $ docker export $(docker create busybox) | tar -C rootfs -xvf - ``` -Prepare a configuration file for the container that will run `sleep 5`. +Then, we need to prepare a configuration file. This file contains metadata and specs for a container, such as the process to run, environment variables to inject, sandboxing features to use, etc. ```sh -$ curl https://gist.githubusercontent.com/utam0k/8ab419996633066eaf53ac9c66d962e7/raw/e81548f591f26ec03d85ce38b0443144573b4cf6/config.json -o config.json -$ cd ../ -$ ./youki create -b tutorial tutorial_container -$ ./youki state tutorial_container # You can see the state the container is in as it is being generate. -$ ./youki start tutorial_container -$ ./youki state tutorial_container # Run it within 5 seconds to see the running container. -$ ./youki delete tutorial_container # Run it after the container is finished running. +$ ./youki spec # will generate a spec file named config.json ``` -Change the command to be executed in config.json and try something other than `sleep 5`. +We can edit the `config.json` to add customized behaviors for container. Here, we modify the `process` field to run `sleep 30`. + +```json + "process": { + "terminal": true, + "user": { + "uid": 0, + "gid": 0 + }, + "args": [ + "sleep", "30" + ], + + ... + } +``` + +Then we can explore the lifecycle of a container: +```sh +$ sudo ./youki create first-container # create a container with name `first-container` +$ sudo ./youki state first-container # you can see the state the container is `created` +$ sudo ./youki start first-container # start the container +$ sudo ./youki list # will show the list of containers, the container is `running` +$ sudo ./youki delete first-container # delete the container +``` + +Change the command to be executed in `config.json` and try something other than `sleep 30`. ## Usage @@ -171,8 +191,9 @@ $ git clone git@github.com:containers/youki.git $ cd youki $ vagrant up $ vagrant ssh + # in virtual machine -$ cd youki # in virtual machine +$ cd youki $ ./build.sh ``` From 29fb64aca9f96541bb68c1740f51f79c5ca8838a Mon Sep 17 00:00:00 2001 From: yukang Date: Thu, 26 Aug 2021 13:32:04 +0000 Subject: [PATCH 2/3] fix readme for missing pkg --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d959ede19..0465ce3ed 100644 --- a/README.md +++ b/README.md @@ -64,10 +64,8 @@ For other platforms, please use [Vagrantfile](#setting-up-vagrant) that we prepa ### Debian, Ubuntu and related distributions ```sh -$ sudo apt-get install \ - pkg-config \ - libsystemd-dev \ - libdbus-glib-1-dev +$ sudo apt-get install pkg-config build-essential libsystemd-dev \ + libdbus-glib-1-dev ``` ### Fedora, Centos, RHEL and related distributions From 4eb5b3fe751d1fd751151a4e3fb030fdfe030d68 Mon Sep 17 00:00:00 2001 From: yukang Date: Fri, 27 Aug 2021 08:01:17 +0000 Subject: [PATCH 3/3] tweak readme tutorial --- .gitignore | 5 ----- README.md | 29 ++++++++++++++--------------- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 27ec3d616..f3ea879a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ youki /tutorial -/rootfs - .idea/ **/target @@ -11,6 +9,3 @@ youki tags tags.lock tags.temp -/config.json - - diff --git a/README.md b/README.md index 0465ce3ed..331cac336 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,11 @@ For other platforms, please use [Vagrantfile](#setting-up-vagrant) that we prepa ### Debian, Ubuntu and related distributions ```sh -$ sudo apt-get install pkg-config build-essential libsystemd-dev \ - libdbus-glib-1-dev +$ sudo apt-get install \ + pkg-config \ + libsystemd-dev \ + libdbus-glib-1-dev \ + build-essential ``` ### Fedora, Centos, RHEL and related distributions @@ -95,8 +98,8 @@ $ git clone git@github.com:containers/youki.git $ cd youki $ ./build.sh -$ mkdir rootfs - +$ mkdir -p tutorial/rootfs +$ cd tutorial # use docker to export busybox into the rootfs directory $ docker export $(docker create busybox) | tar -C rootfs -xvf - ``` @@ -104,18 +107,14 @@ $ docker export $(docker create busybox) | tar -C rootfs -xvf - Then, we need to prepare a configuration file. This file contains metadata and specs for a container, such as the process to run, environment variables to inject, sandboxing features to use, etc. ```sh -$ ./youki spec # will generate a spec file named config.json +$ ../youki spec # will generate a spec file named config.json ``` We can edit the `config.json` to add customized behaviors for container. Here, we modify the `process` field to run `sleep 30`. ```json "process": { - "terminal": true, - "user": { - "uid": 0, - "gid": 0 - }, + ... "args": [ "sleep", "30" ], @@ -126,11 +125,11 @@ We can edit the `config.json` to add customized behaviors for container. Here, w Then we can explore the lifecycle of a container: ```sh -$ sudo ./youki create first-container # create a container with name `first-container` -$ sudo ./youki state first-container # you can see the state the container is `created` -$ sudo ./youki start first-container # start the container -$ sudo ./youki list # will show the list of containers, the container is `running` -$ sudo ./youki delete first-container # delete the container +$ sudo ./youki create -b tutorial tutorial_container # create a container with name `tutorial_container` +$ sudo ./youki state tutorial_container # you can see the state the container is `created` +$ sudo ./youki start tutorial_container # start the container +$ sudo ./youki list # will show the list of containers, the container is `running` +$ sudo ./youki delete tutorial_container # delete the container ``` Change the command to be executed in `config.json` and try something other than `sleep 30`.