Skip to content

Commit 284490d

Browse files
r3d91llTodd W Bucy
and
Todd W Bucy
authored
Docker Documentation (microsoft#1251)
* Updates to the Dockerfiles making them more secure. update to the installation.md file and a start.sh file for the Dockerfile.dev to start the document server. Not ready for pull request. * updates to the docker documentation * clean up before commit * added docker instructions on how to test documentation prior to commit. * fixed the title heading in the installation.md * removed alternate yarn install from Dockerfile.dev * Update sidebars.js removed un-related change from website/sidebars.js * cleaned up the lint errors from the pre-commit-check. * removed bad edit from sidebars.js * fixing git conflict with sidebars.js file * Update Installation.md added the missing sections back. However, do we still want the docker section under the Optional Dependencies? That looks like it would go better in the Dockerfiles.md file. * Update Installation.md Added mount your code back and added mount your directory for better clarity. * Update Installation.md Lint cleanup * Update Installation.md removed the relative path to samples/dockers/Dockerfiles.md with a proper URL to where it will exist * fixed bad link to Dockerfiles.md * Fix trailing whitespace and formatting issues * Update link to Dockerfiles.md * somtimes its really hard to find that lost i. * trailing whitespace and EOF issues resolved * fixed broken link * trailing space an broken link * removed broken links. will update one merged. * fixed glaring error about building an image from a particular branch Contribute.md * removed tic mark typo from contribute.md --------- Co-authored-by: Todd W Bucy <todd.bucy@rackspace>
1 parent e6c044b commit 284490d

File tree

6 files changed

+340
-121
lines changed

6 files changed

+340
-121
lines changed

samples/dockers/Dockerfile.base

+18-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
FROM python:3.11-slim-bookworm
22

3-
RUN : \
4-
&& apt-get update \
3+
RUN apt-get update \
54
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
6-
software-properties-common \
7-
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
8-
python3-venv \
5+
software-properties-common sudo\
96
&& apt-get clean \
10-
&& rm -rf /var/lib/apt/lists/* \
11-
&& :
7+
&& rm -rf /var/lib/apt/lists/*
8+
9+
# Setup a non-root user 'autogen' with sudo access
10+
RUN adduser --disabled-password --gecos '' autogen
11+
RUN adduser autogen sudo
12+
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
13+
USER autogen
14+
WORKDIR /home/autogen
1215

13-
RUN python3 -m venv /venv
14-
ENV PATH=/venv/bin:$PATH
15-
EXPOSE 8081
16+
# Set environment variable if needed
17+
# ENV OPENAI_API_KEY="{OpenAI-API-Key}"
1618

17-
RUN cd /venv; pip install pyautogen
1819
# Pre-load popular packages as per https://learnpython.com/blog/most-popular-python-packages/
19-
RUN pip install numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4
20+
RUN pip install pyautogen numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4
21+
22+
# Expose port
23+
# EXPOSE 8081
2024

21-
ENTRYPOINT []
25+
# Start Command
26+
CMD [ "/bin/bash" ]

samples/dockers/Dockerfile.dev

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,42 @@
1-
# basic setup
1+
# Basic setup
22
FROM python:3.11-slim-bookworm
3+
4+
# Update and install necessary packages
35
RUN apt-get update && apt-get -y update
4-
RUN apt-get install -y sudo git npm
6+
# added vim and nano for convenience
7+
RUN apt-get install -y sudo git npm vim nano curl
58

6-
# Setup user to not run as root
7-
RUN adduser --disabled-password --gecos '' autogen-dev
8-
RUN adduser autogen-dev sudo
9+
# Setup a non-root user 'autogen' with sudo access
10+
RUN adduser --disabled-password --gecos '' autogen
11+
RUN adduser autogen sudo
912
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
10-
USER autogen-dev
13+
USER autogen
14+
WORKDIR /home/autogen
15+
16+
# Set environment variable
17+
# ENV OPENAI_API_KEY="{OpenAI-API-Key}"
1118

12-
# Pull repo
13-
RUN cd /home/autogen-dev && git clone https://github.com/microsoft/autogen.git
14-
WORKDIR /home/autogen-dev/autogen
19+
# Clone the AutoGen repository
20+
RUN git clone https://github.com/microsoft/autogen.git /home/autogen/autogen
21+
WORKDIR /home/autogen/autogen
1522

16-
# Install autogen in editable mode (Note: extra components can be installed if needed)
23+
# Install AutoGen in editable mode with extra components
1724
RUN sudo pip install -e .[test,teachable,lmm,retrievechat,mathchat,blendsearch]
1825

19-
# Install precommit hooks
26+
# Install pre-commit hooks
2027
RUN pre-commit install
2128

22-
# For docs
29+
# Setup Docusaurus and Yarn for the documentation website
2330
RUN sudo npm install --global yarn
2431
RUN sudo pip install pydoc-markdown
2532
RUN cd website
2633
RUN yarn install --frozen-lockfile --ignore-engines
2734

28-
# Pre-load popular packages as per https://learnpython.com/blog/most-popular-python-packages/
35+
# Exposes the Yarn port for Docusaurus
36+
EXPOSE 3000
37+
38+
# Pre-load popular Python packages
2939
RUN pip install numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4
3040

31-
# override default image starting point
32-
CMD /bin/bash
33-
ENTRYPOINT []
41+
# Set the default command to bash
42+
CMD ["/bin/bash"]

samples/dockers/Dockerfile.full

+21-13
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
FROM python:3.11-slim-bookworm
22

3-
RUN : \
4-
&& apt-get update \
3+
# Update and install dependencies
4+
RUN apt-get update \
55
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
6-
software-properties-common \
7-
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
8-
python3-venv \
6+
software-properties-common sudo\
97
&& apt-get clean \
10-
&& rm -rf /var/lib/apt/lists/* \
11-
&& :
8+
&& rm -rf /var/lib/apt/lists/*
129

13-
RUN python3 -m venv /venv
14-
ENV PATH=/venv/bin:$PATH
15-
EXPOSE 8081
10+
# Setup a non-root user 'autogen' with sudo access
11+
RUN adduser --disabled-password --gecos '' autogen
12+
RUN adduser autogen sudo
13+
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
14+
USER autogen
15+
WORKDIR /home/autogen
16+
17+
# Set environment variable if needed
18+
# ENV OPENAI_API_KEY="{OpenAI-API-Key}"
1619

17-
RUN cd /venv; pip install pyautogen[teachable,lmm,retrievechat,mathchat,blendsearch] autogenra
18-
# Pre-load popular packages as per https://learnpython.com/blog/most-popular-python-packages/
20+
# Install Python packages
21+
RUN pip install --upgrade pip
22+
RUN pip install pyautogen[teachable,lmm,retrievechat,mathchat,blendsearch] autogenra
1923
RUN pip install numpy pandas matplotlib seaborn scikit-learn requests urllib3 nltk pillow pytest beautifulsoup4
2024

21-
ENTRYPOINT []
25+
# Expose port
26+
EXPOSE 8081
27+
28+
# Start Command
29+
CMD ["/bin/bash"]

samples/dockers/Dockerfiles.md

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# README for AutoGen Docker Samples
2+
3+
Welcome to the `autogen/samples/dockers` directory! Here you'll find Dockerfiles that are essential for setting up your AutoGen development environment. Each Dockerfile is tailored for different use cases and requirements. Below is a brief overview of each and how you can utilize them effectively.
4+
5+
## Dockerfile Descriptions
6+
7+
### Dockerfile.base
8+
9+
- **Purpose**: This Dockerfile is designed for basic setups. It includes common Python libraries and essential dependencies required for general usage of AutoGen.
10+
- **Usage**: Ideal for those just starting with AutoGen or for general-purpose applications.
11+
- **Building the Image**: Run `docker build -f Dockerfile.base -t autogen_base_img .` in this directory.
12+
13+
### Dockerfile.full
14+
15+
- **Purpose**: This Dockerfile is for advanced features. It includes additional dependencies and is configured for more complex or feature-rich AutoGen applications.
16+
- **Usage**: Suited for advanced users who need the full range of AutoGen's capabilities.
17+
- **Building the Image**: Execute `docker build -f Dockerfile.full -t autogen_full_img .`.
18+
19+
### Dockerfile.dev
20+
21+
- **Purpose**: Tailored for AutoGen project developers, this Dockerfile includes tools and configurations aiding in development and contribution.
22+
- **Usage**: Recommended for developers who are contributing to the AutoGen project.
23+
- **Building the Image**: Run `docker build -f Dockerfile.dev -t autogen_dev_img .`.
24+
- **Before using**: We highly encourage all potential contributors to read the [AutoGen Contributing](https://microsoft.github.io/autogen/docs/Contribute) page prior to submitting any pull requests.
25+
26+
## Customizing Dockerfiles
27+
28+
Feel free to modify these Dockerfiles for your specific project needs. Here are some common customizations:
29+
30+
- **Adding New Dependencies**: If your project requires additional Python packages, you can add them using the `RUN pip install` command.
31+
- **Changing the Base Image**: You may change the base image (e.g., from a Python image to an Ubuntu image) to suit your project's requirements.
32+
- **Changing the Python version**: do you need a different version of python other than 3.11. Just update the first line of each of the Dockerfiles like so:
33+
`FROM python:3.11-slim-bookworm` to `FROM python:3.10-slim-bookworm`
34+
- **Setting Environment Variables**: Add environment variables using the `ENV` command for any application-specific configurations. We have prestaged the line needed to inject your OpenAI_key into the docker environment as a environmental variable. Others can be staged in the same way. Just uncomment the line.
35+
`# ENV OPENAI_API_KEY="{OpenAI-API-Key}"` to `ENV OPENAI_API_KEY="{OpenAI-API-Key}"`
36+
- **Need a less "Advanced" Autogen build**: If the Dockerfile.full is to much but you need more than advanced then update this line in the Dockerfile.full file.
37+
`RUN pip install pyautogen[teachable,lmm,retrievechat,mathchat,blendsearch] autogenra` to install just what you need. `RUN pip install pyautogen[retrievechat,blendsearch] autogenra`
38+
- **Can't Dev without your favorite CLI tool**: if you need particular OS tools to be installed in your Docker container you can add those packages here right after the sudo for the Dockerfile.base and Dockerfile.full files. In the example below we are installing net-tools and vim to the environment.
39+
40+
```code
41+
RUN apt-get update \
42+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
43+
software-properties-common sudo net-tools vim\
44+
&& apt-get clean \
45+
&& rm -rf /var/lib/apt/lists/*
46+
```
47+
48+
### Managing Your Docker Environment
49+
50+
After customizing your Dockerfile, build the Docker image using the `docker build` command as shown above. To run a container based on your new image, use:
51+
52+
```bash
53+
docker run -it -v $(pwd)/your_app:/app your_image_name
54+
```
55+
56+
Replace `your_app` with your application directory and `your_image_name` with the name of the image you built.
57+
58+
#### Closing for the Day
59+
60+
- **Exit the container**: Type `exit`.
61+
- **Stop the container**: Use `docker stop {application_project_name}`.
62+
63+
#### Resuming Work
64+
65+
- **Restart the container**: Use `docker start {application_project_name}`.
66+
- **Access the container**: Execute `sudo docker exec -it {application_project_name} bash`.
67+
- **Reactivate the environment**: Run `source /usr/src/app/autogen_env/bin/activate`.
68+
69+
### Useful Docker Commands
70+
71+
- **View running containers**: `docker ps -a`.
72+
- **View Docker images**: `docker images`.
73+
- **Restart container setup**: Stop (`docker stop my_container`), remove the container (`docker rm my_container`), and remove the image (`docker rmi my_image:latest`).
74+
75+
#### Troubleshooting Common Issues
76+
77+
- Check Docker daemon, port conflicts, and permissions issues.
78+
79+
#### Additional Resources
80+
81+
For more information on Docker usage and best practices, refer to the [official Docker documentation](https://docs.docker.com).

0 commit comments

Comments
 (0)