Docker is a game-changing technology that enables us to run applications locally. We package our Apps into Containers that include everything needed to run the application

Docker Resources

Phidata enables us to define docker resources as pydantic objects so we can build our application layer purely in python. In most cases you will not be creating the Docker Resources directly, instead we’ll use Apps to create the resources for us.


  • Define containers and images as pydantic objects with input and type validation.
  • Allows re-use and testing of resources.
  • Import them in software layer like regular python objects.
  • Package multiple resources into Apps so we can define “Applications as Code”.
  • Enable AI features that interact with the resource from python code.


The DockerContainer class defines a container, for example use the following code to define a container running the whoami image. Start it using phi start
from phi.docker.resource.container import DockerContainer

whoami = DockerContainer(
    ports={'80': 80},

Test it by opening http://localhost:80 or using:

curl -X POST http://localhost:80

The same can be defined as an App:
from import Whoami

whoami = Whoami()

Stop resources using phi stop


The DockerImage class defines an image, for example use the following code create your own python image and run it in a container. Build it using phi start

from phi.docker.resource.container import DockerContainer
from phi.docker.resource.image import DockerImage

python_image = DockerImage(
    # push_image=True,

python_container = DockerContainer(

Make sure to add the Dockerfile in the current directory.