Docker
Docker, an indispensable tool in modern software development, offers a compelling solution for AG2’s setup. Docker allows you to create consistent environments that are portable and isolated from the host OS. With Docker, everything AG2 needs to run, from the operating system to specific libraries, is encapsulated in a container, ensuring uniform functionality across different systems. The Dockerfiles necessary for AG2 are conveniently located in the project’s GitHub repository at https://github.com/ag2ai/ag2/tree/main/.devcontainer.
Pre-configured DockerFiles: The AG2 Project offers pre-configured Dockerfiles for your use. These Dockerfiles will run as is, however they can be modified to suit your development needs. Please see the README.md file in autogen/.devcontainer
- ag2_base_img: For a basic setup, you can use the
ag2_base_img
to run simple scripts or applications. This is ideal for general users or those new to AG2. - ag2_full_img: Advanced users or those requiring more features can use
ag2_full_img
. Be aware that this version loads ALL THE THINGS and thus is very large. Take this into consideration if you build your application off of it.
Step 1: Install Docker
-
General Installation: Follow the official Docker installation instructions. This is your first step towards a containerized environment, ensuring a consistent and isolated workspace for AG2.
-
For Mac Users: If you encounter issues with the Docker daemon, consider using colima. Colima offers a lightweight alternative to manage Docker containers efficiently on macOS.
Step 2: Build a Docker Image
AG2 now provides updated Dockerfiles tailored for different needs. Building a Docker image is akin to setting the foundation for your project’s environment:
-
AG2 Basic: Ideal for general use, this setup includes common Python libraries and essential dependencies. Perfect for those just starting with AG2.
-
AG2 Advanced: Advanced users or those requiring all the things that AG2 has to offer
ag2_full_img
Step 3: Run AG2 Applications from Docker Image
Here’s how you can run an application built with AG2, using the Docker image:
-
Mount Your Directory: Use the Docker
-v
flag to mount your local application directory to the Docker container. This allows you to develop on your local machine while running the code in a consistent Docker environment. For example:Here,
$(pwd)/myapp
is your local directory, and/home/ag2ai/ag2/myapp
is the path in the Docker container where your code will be located. -
Mount your code: Now suppose you have your application built with AG2 in a main script named
twoagent.py
(example) in a folder namedmyapp
. With the command line below, you can mount your folder and run the application in Docker. -
Port Mapping: If your application requires a specific port, use the
-p
flag to map the container’s port to your host. For instance, if your app runs on port 3000 inside Docker and you want it accessible on port 8080 on your host machine:In this command,
-p 8080:3000
maps port 3000 from the container to port 8080 on your local machine. -
Examples of Running Different Applications: Here is the basic format of the docker run command.
-
Simple Script: Run a Python script located in your local
myapp
directory. -
Web Application: If your application includes a web server running on port 5000.
-
Data Processing: For tasks that involve processing data stored in a local directory.
Additional Resources
- Details on all the Dockerfile options can be found in the Dockerfile README.
- For more information on Docker usage and best practices, refer to the official Docker documentation.
- Details on how to use the Dockerfile dev version can be found on the Contributor Guide.