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
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.
difference from docker-compose
Docker Compose is more mature and defines resources as a “yaml configuration” whereas phidata allows us to define resources as “python objects”.
We still love docker-compose, just want to elevate the experience. With phidata we rarely define the resources directly, instead we use Apps to create the resources for us.
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 resources.py
Test it by opening http://localhost:80 or using:
The same can be defined as an App
:
Stop resources using phi stop resources.py
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 resources.py
Make sure to add the Dockerfile
in the current directory.