1# SPDK and Containers {#containers} 2 3This is a living document as there are many ways to use containers with 4SPDK. As new usages are identified and tested, they will be documented 5here. 6 7## In this document {#containers_toc} 8 9* @ref spdk_in_docker 10* @ref spdk_docker_suite 11* @ref kata_containers_with_spdk_vhost 12 13## Containerizing an SPDK Application for Docker {#spdk_in_docker} 14 15There are no SPDK specific changes needed to run an SPDK based application in 16a docker container, however this quick start guide should help you as you 17containerize your SPDK based application. 18 191. Make sure you have all of your app dependencies identified and included in your Dockerfile 202. Make sure you have compiled your application for the target arch 213. Make sure your host has hugepages enabled 224. Make sure your host has bound your nvme device to your userspace driver 235. Write your Dockerfile. The following is a simple Dockerfile to containerize the nvme `hello_world` 24 example: 25 26~~~{.sh} 27# start with the latest Fedora 28FROM fedora 29 30# if you are behind a proxy, set that up now 31ADD dnf.conf /etc/dnf/dnf.conf 32 33# these are the min dependencies for the hello_world app 34RUN dnf install libaio-devel -y 35RUN dnf install numactl-devel -y 36 37# set our working dir 38WORKDIR /app 39 40# add the hello_world binary 41ADD hello_world hello_world 42 43# run the app 44CMD ./hello_world 45~~~ 46 476. Create your image 48 49`sudo docker image build -t hello:1.0 .` 50 517. You docker command line will need to include at least the following: 52- the `--privileged` flag to enable sharing of hugepages 53- use of the `-v` switch to map hugepages 54 55`sudo docker run --privileged -v /dev/hugepages:/dev/hugepages hello:1.0` 56 57or depending on the needs of your app you may need one or more of the following parameters: 58 59- If you are using the SPDK app framework: `-v /dev/shm:/dev/shm` 60- If you need to use RPCs from outside of the container: `-v /var/tmp:/var/tmp` 61- If you need to use the host network (i.e. NVMF target application): `--network host` 62 63Your output should look something like this: 64 65~~~{.sh} 66$ sudo docker run --privileged -v //dev//hugepages://dev//hugepages hello:1.0 67Starting SPDK v20.01-pre git sha1 80da95481 // DPDK 19.11.0 initialization... 68[ DPDK EAL parameters: hello_world -c 0x1 --log-level=lib.eal:6 --log-level=lib.cryptodev:5 --log-level=user1:6 --iova-mode=pa 69--base-virtaddr=0x200000000000 --match-allocations --file-prefix=spdk0 --proc-type=auto ] 70EAL: No available hugepages reported in hugepages-1048576kB 71Initializing NVMe Controllers 72Attaching to 0000:06:00.0 73Attached to 0000:06:00.0 74Using controller INTEL SSDPEDMD400G4 (CVFT7203005M400LGN ) with 1 namespaces. 75 Namespace ID: 1 size: 400GB 76Initialization complete. 77INFO: using host memory buffer for IO 78Hello world! 79~~~ 80 81## SPDK Docker suite {#spdk_docker_suite} 82 83When considering how to generate SPDK docker container images formally, 84deploy SPDK containers correctly, interact with SPDK container instances, 85and orchestrate SPDK container instances, you can get practiced and inspired from 86this SPDK docker-compose example: 87[SPDK Docker suite](https://github.com/spdk/spdk/blob/master/docker/README.md). 88 89## Using SPDK vhost target to provide volume service to Kata Containers and Docker {#kata_containers_with_spdk_vhost} 90 91[Kata Containers](https://katacontainers.io) can build a secure container 92runtime with lightweight virtual machines that feel and perform like 93containers, but provide stronger workload isolation using hardware 94virtualization technology as a second layer of defense. 95 96From Kata Containers [1.11.0](https://github.com/kata-containers/runtime/releases/tag/1.11.0), 97vhost-user-blk support is enabled in `kata-containers/runtime`. That is to say 98SPDK vhost target can be used to provide volume service to Kata Containers directly. 99In addition, a container manager like Docker, can be configured easily to launch 100a Kata container with an SPDK vhost-user block device. For operating details, visit 101Kata 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