diff --git a/docker-example/Dockerfile b/docker-example/Dockerfile new file mode 100644 index 00000000000..6bd10489759 --- /dev/null +++ b/docker-example/Dockerfile @@ -0,0 +1,49 @@ +FROM python:3.11-slim as base + +RUN adduser --disabled-password pynecone + + +FROM base as build + +WORKDIR /app +ENV VIRTUAL_ENV=/app/venv +RUN python3 -m venv $VIRTUAL_ENV +ENV PATH="$VIRTUAL_ENV/bin:$PATH" + +COPY . . + +RUN pip install wheel \ + && pip install -r requirements.txt + + +FROM base as runtime + +RUN apt-get update && apt-get install -y \ + curl \ + && curl -fsSL https://deb.nodesource.com/setup_19.x | bash - \ + && apt-get update && apt-get install -y \ + nodejs \ + unzip \ + && rm -rf /var/lib/apt/lists/* + +ENV PATH="/app/venv/bin:$PATH" + + +FROM runtime as init + +WORKDIR /app +ENV BUN_INSTALL="/app/.bun" +COPY --from=build /app/ /app/ +RUN pc init + + +FROM runtime + +COPY --chown=pynecone --from=init /app/ /app/ +USER pynecone +WORKDIR /app + +CMD ["pc","run" , "--env", "prod"] + +EXPOSE 3000 +EXPOSE 8000 diff --git a/docker-example/README.md b/docker-example/README.md new file mode 100644 index 00000000000..6870cec3dcb --- /dev/null +++ b/docker-example/README.md @@ -0,0 +1,33 @@ +# Pynecone Container Image Build +This example describes how to create and use a container image for Pynecone with your own code. + +## Update Requirements +The `requirements.txt` includes the pynecone-io package which is need to install Pynecone framework. If you use additional packages in your project you have add this in the `requirements.txt` first. Copy the `Dockerfile` and the `requirements.txt` file in your project folder. + +## Customize Pynecone Config +The `pcconfig.py` includes the configuration of your Pynecone service. Edit the file like the following configuration. If you want to use a custom database you can set the endpoint in this file. + +```python +import pynecone as pc + +config = pc.Config( + app_name="app", + api_url="0.0.0.0:8000", + bun_path="/app/.bun/bin/bun", + db_url="sqlite:///pynecone.db", +) +``` + +## Build Pyonecone Container Image +To build your container image run the following command: + +```bash +docker build -t pynecone-project:latest . +``` + +## Start Container Service +Finally, you can start your Pynecone container service as follows: + +```bash +docker run -d -p 3000:3000 -p 8000:8000 --name pynecone pynecone:latest +``` \ No newline at end of file diff --git a/docker-example/requirements.txt b/docker-example/requirements.txt new file mode 100644 index 00000000000..b89653ac77a --- /dev/null +++ b/docker-example/requirements.txt @@ -0,0 +1 @@ +pynecone-io \ No newline at end of file