xref: /spdk/doc/containers.md (revision 03b75034ae30510c33f3a2c0a102d9cceacedd90)
187dcedb8Spaul luse# SPDK and Containers {#containers}
287dcedb8Spaul luse
387dcedb8Spaul luseThis is a living document as there are many ways to use containers with
487dcedb8Spaul luseSPDK. As new usages are identified and tested, they will be documented
587dcedb8Spaul lusehere.
687dcedb8Spaul luse
71e1fd9acSwawryk## In this document {#containers_toc}
887dcedb8Spaul luse
987dcedb8Spaul luse* @ref spdk_in_docker
10*03b75034SLiu Xiaodong* @ref spdk_docker_suite
11a4c5411bSLiu Xiaodong* @ref kata_containers_with_spdk_vhost
12a919a310SLiu Xiaodong
131e1fd9acSwawryk## Containerizing an SPDK Application for Docker {#spdk_in_docker}
1487dcedb8Spaul luse
1587dcedb8Spaul luseThere are no SPDK specific changes needed to run an SPDK based application in
1687dcedb8Spaul lusea docker container, however this quick start guide should help you as you
1787dcedb8Spaul lusecontainerize your SPDK based application.
1887dcedb8Spaul luse
1987dcedb8Spaul luse1. Make sure you have all of your app dependencies identified and included in your Dockerfile
2087dcedb8Spaul luse2. Make sure you have compiled your application for the target arch
2187dcedb8Spaul luse3. Make sure your host has hugepages enabled
2287dcedb8Spaul luse4. Make sure your host has bound your nvme device to your userspace driver
2387dcedb8Spaul luse5. Write your Dockerfile. The following is a simple Dockerfile to containerize the nvme `hello_world`
2487dcedb8Spaul luse  example:
2587dcedb8Spaul luse
2687dcedb8Spaul luse~~~{.sh}
2787dcedb8Spaul luse# start with the latest Fedora
2887dcedb8Spaul luseFROM fedora
2987dcedb8Spaul luse
3087dcedb8Spaul luse# if you are behind a proxy, set that up now
3187dcedb8Spaul luseADD dnf.conf /etc/dnf/dnf.conf
3287dcedb8Spaul luse
3387dcedb8Spaul luse# these are the min dependencies for the hello_world app
3487dcedb8Spaul luseRUN dnf install libaio-devel -y
3587dcedb8Spaul luseRUN dnf install numactl-devel -y
3687dcedb8Spaul luse
3787dcedb8Spaul luse# set our working dir
3887dcedb8Spaul luseWORKDIR /app
3987dcedb8Spaul luse
4087dcedb8Spaul luse# add the hello_world binary
4187dcedb8Spaul luseADD hello_world hello_world
4287dcedb8Spaul luse
4387dcedb8Spaul luse# run the app
4487dcedb8Spaul luseCMD ./hello_world
4587dcedb8Spaul luse~~~
4687dcedb8Spaul luse
4787dcedb8Spaul luse6. Create your image
4887dcedb8Spaul luse
4987dcedb8Spaul luse`sudo docker image build -t hello:1.0 .`
5087dcedb8Spaul luse
5187dcedb8Spaul luse7. You docker command line will need to include at least the following:
5287dcedb8Spaul luse- the `--privileged` flag to enable sharing of hugepages
5387dcedb8Spaul luse- use of the `-v` switch to map hugepages
5487dcedb8Spaul luse
5587dcedb8Spaul luse`sudo docker run --privileged -v /dev/hugepages:/dev/hugepages hello:1.0`
5687dcedb8Spaul luse
5787dcedb8Spaul luseor depending on the needs of your app you may need one or more of the following parameters:
5887dcedb8Spaul luse
5987dcedb8Spaul luse- If you are using the SPDK app framework: `-v /dev/shm:/dev/shm`
6087dcedb8Spaul luse- If you need to use RPCs from outside of the container: `-v /var/tmp:/var/tmp`
6187dcedb8Spaul luse- If you need to use the host network (i.e. NVMF target application): `--network host`
6287dcedb8Spaul luse
6387dcedb8Spaul luseYour output should look something like this:
6487dcedb8Spaul luse
6587dcedb8Spaul luse~~~{.sh}
6687dcedb8Spaul luse$ sudo docker run --privileged -v //dev//hugepages://dev//hugepages hello:1.0
6787dcedb8Spaul luseStarting SPDK v20.01-pre git sha1 80da95481 // DPDK 19.11.0 initialization...
6812fcbc9bSwawryk[ DPDK EAL parameters: hello_world -c 0x1 --log-level=lib.eal:6 --log-level=lib.cryptodev:5 --log-level=user1:6 --iova-mode=pa
6912fcbc9bSwawryk--base-virtaddr=0x200000000000 --match-allocations --file-prefix=spdk0 --proc-type=auto ]
7087dcedb8Spaul luseEAL: No available hugepages reported in hugepages-1048576kB
7187dcedb8Spaul luseInitializing NVMe Controllers
7287dcedb8Spaul luseAttaching to 0000:06:00.0
7387dcedb8Spaul luseAttached to 0000:06:00.0
7487dcedb8Spaul luseUsing controller INTEL SSDPEDMD400G4  (CVFT7203005M400LGN  ) with 1 namespaces.
7587dcedb8Spaul luse  Namespace ID: 1 size: 400GB
7687dcedb8Spaul luseInitialization complete.
7787dcedb8Spaul luseINFO: using host memory buffer for IO
7887dcedb8Spaul luseHello world!
7987dcedb8Spaul luse~~~
80a4c5411bSLiu Xiaodong
81*03b75034SLiu Xiaodong## SPDK Docker suite {#spdk_docker_suite}
82*03b75034SLiu Xiaodong
83*03b75034SLiu XiaodongWhen considering how to generate SPDK docker container images formally,
84*03b75034SLiu Xiaodongdeploy SPDK containers correctly, interact with SPDK container instances,
85*03b75034SLiu Xiaodongand orchestrate SPDK container instances, you can get practiced and inspired from
86*03b75034SLiu Xiaodongthis SPDK docker-compose example:
87*03b75034SLiu Xiaodong[SPDK Docker suite](https://github.com/spdk/spdk/blob/master/docker/README.md).
88*03b75034SLiu Xiaodong
89a4c5411bSLiu Xiaodong## Using SPDK vhost target to provide volume service to Kata Containers and Docker {#kata_containers_with_spdk_vhost}
90a4c5411bSLiu Xiaodong
91a4c5411bSLiu Xiaodong[Kata Containers](https://katacontainers.io) can build a secure container
92a4c5411bSLiu Xiaodongruntime with lightweight virtual machines that feel and perform like
93a4c5411bSLiu Xiaodongcontainers, but provide stronger workload isolation using hardware
94a4c5411bSLiu Xiaodongvirtualization technology as a second layer of defense.
95a4c5411bSLiu Xiaodong
96a4c5411bSLiu XiaodongFrom Kata Containers [1.11.0](https://github.com/kata-containers/runtime/releases/tag/1.11.0),
97a4c5411bSLiu Xiaodongvhost-user-blk support is enabled in `kata-containers/runtime`. That is to say
98a4c5411bSLiu XiaodongSPDK vhost target can be used to provide volume service to Kata Containers directly.
99a4c5411bSLiu XiaodongIn addition, a container manager like Docker, can be configured easily to launch
100a4c5411bSLiu Xiaodonga Kata container with an SPDK vhost-user block device. For operating details, visit
101a4c5411bSLiu XiaodongKata containers use-case [Setup to run SPDK vhost-user devices with Kata Containers and Docker](https://github.com/kata-containers/documentation/blob/master/use-cases/using-SPDK-vhostuser-and-kata.md#host-setup-for-vhost-user-devices)
102