|
| 1 | +<!-- markdownlint-disable first-line-heading --> |
| 2 | +<p align="center"> |
| 3 | + <a href="https://hub.docker.com/r/mgldvd/slim-python3-uv" target="_blank"><img src="https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/.github/assets/mgldvd-docker-banner.png" alt="Mgldvd-Docker" height="auto" /></a> |
| 4 | +</p> |
| 5 | + |
| 6 | +# slim Python3 + uv Docker Image |
| 7 | + |
| 8 | +<p float="left"> |
| 9 | + <img src="https://cdn.svgporn.com/logos/docker.svg" height="40" title="docker"> |
| 10 | + <img src="https://www.svgrepo.com/show/304556/three-dots.svg" height="30" title="dots"> |
| 11 | + <img src="https://cdn.svglogos.dev/logos/python.svg" height="40" title="python"> |
| 12 | +</p> |
| 13 | + |
| 14 | +**Docker + Python 3 + uv** |
| 15 | + |
| 16 | +This repo builds the `mgldvd/slim-python3-uv` Docker image on top of `python:3-slim`, adding Bash tooling and uv. |
| 17 | + |
| 18 | +- **GitHub**: https://github.com/Mgldvd-Docker/slim-python3-uv |
| 19 | +- **Docker Hub**: https://hub.docker.com/r/mgldvd/slim-python3-uv |
| 20 | + |
| 21 | +## π§ Overview |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +Single Dockerfile using slim and Python 3 with uv preinstalled, published by the GitHub Actions workflow on `deploy/hub`. |
| 26 | + |
| 27 | +### π¦ Packages installed via `apk add` |
| 28 | + |
| 29 | +- `bash` |
| 30 | +- `sudo` |
| 31 | +- `curl` |
| 32 | +- `ca-certificates` |
| 33 | +- `neovim` |
| 34 | +- `coreutils` |
| 35 | +- `git` |
| 36 | + |
| 37 | +### π§ Added tooling |
| 38 | + |
| 39 | +- uv installed via the official installer and linked at `/usr/local/bin/uv` |
| 40 | +- Non-root user `master` with passwordless sudo |
| 41 | +- Bash profile with a custom prompt, `ll` helper, and `vim` alias to `nvim` |
| 42 | +- Working directory `/app` owned by `master` |
| 43 | + |
| 44 | +## π·οΈ Image Tags |
| 45 | + |
| 46 | +| Tag | Description | |
| 47 | +| --- | --- | |
| 48 | +| `latest` | Most recent successful build on `deploy/hub` | |
| 49 | + |
| 50 | +## βοΈ Docker Hub |
| 51 | + |
| 52 | +### π Quick start |
| 53 | + |
| 54 | +```sh |
| 55 | +docker run --rm -it -v "$PWD:/app" mgldvd/slim-python3-uv bash |
| 56 | +``` |
| 57 | + |
| 58 | +### π§ͺ Python requests example |
| 59 | + |
| 60 | +Inside the container: |
| 61 | + |
| 62 | +```sh |
| 63 | +uv init requests-demo |
| 64 | + |
| 65 | +cd requests-demo |
| 66 | + |
| 67 | +uv add requests |
| 68 | +``` |
| 69 | + |
| 70 | +```sh |
| 71 | +cat <<'PY' > main.py |
| 72 | +import requests |
| 73 | +
|
| 74 | +
|
| 75 | +def main() -> None: |
| 76 | + response = requests.get("https://httpbin.org/json", timeout=5) |
| 77 | + print(response.json()["slideshow"]["title"]) |
| 78 | +
|
| 79 | +
|
| 80 | +if __name__ == "__main__": |
| 81 | + main() |
| 82 | +PY |
| 83 | +``` |
| 84 | + |
| 85 | +```sh |
| 86 | +uv run main.py |
| 87 | +``` |
| 88 | + |
| 89 | +<br> |
| 90 | +<br> |
| 91 | + |
| 92 | +## ποΈ Building Locally |
| 93 | + |
| 94 | +Clone the project and build the image using the provided Dockerfile: |
| 95 | + |
| 96 | +```sh |
| 97 | +git clone https://github.com/Mgldvd-Docker/slim-python3-uv.git |
| 98 | + |
| 99 | +cd slim-python3-uv |
| 100 | +``` |
| 101 | + |
| 102 | +```sh |
| 103 | +docker build -t mgldvd/slim-python3-uv:local . |
| 104 | +``` |
| 105 | + |
| 106 | +Run the container to verify the build: |
| 107 | + |
| 108 | +```sh |
| 109 | +docker run --rm -it -v "$PWD:/app" mgldvd/slim-python3-uv:local bash |
| 110 | +``` |
| 111 | + |
| 112 | +### ποΈ Building Locally (python 3.11) |
| 113 | + |
| 114 | +```sh |
| 115 | +# build |
| 116 | +docker build -t mgldvd/slim-python3.11-uv:local -f Dockerfile.python3-11 . |
| 117 | +# run |
| 118 | +docker run --rm -it -v "$PWD:/app" mgldvd/slim-python3.11-uv:local bash |
| 119 | +``` |
| 120 | + |
| 121 | +<br> |
| 122 | +<br> |
| 123 | + |
| 124 | +### π³ Docker Compose |
| 125 | + |
| 126 | +Use the bundled [compose.yml](https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/compose.yml) to launch an interactive shell with your local `app/` directory mounted into the container: |
| 127 | + |
| 128 | +```sh |
| 129 | +mkdir app |
| 130 | +``` |
| 131 | + |
| 132 | +```sh |
| 133 | +wget https://raw.githubusercontent.com/Mgldvd-Docker/slim-python3-uv/refs/heads/master/compose.yml |
| 134 | +``` |
| 135 | + |
| 136 | +or create file: `compose.yml` |
| 137 | + |
| 138 | +```yml |
| 139 | +services: |
| 140 | + app: |
| 141 | + image: mgldvd/slim-python3-uv |
| 142 | + command: bash |
| 143 | + volumes: |
| 144 | + - ./app:/app |
| 145 | + stdin_open: true |
| 146 | + tty: true |
| 147 | + restart: "no" |
| 148 | +``` |
| 149 | +
|
| 150 | +```sh |
| 151 | +docker compose run --rm app |
| 152 | +``` |
| 153 | + |
| 154 | +To keep the container running in the background instead, start it detached and exec into it when needed: |
| 155 | + |
| 156 | +```sh |
| 157 | +docker compose up -d |
| 158 | +docker compose exec app bash |
| 159 | +``` |
| 160 | + |
| 161 | +<br> |
| 162 | +<br> |
| 163 | + |
| 164 | +## π€ Publishing Workflow |
| 165 | + |
| 166 | +The GitHub Actions workflow at `.github/workflows/docker-publish.yml` automates image publication. It performs the following steps: |
| 167 | + |
| 168 | +1. Checks out the repository. |
| 169 | +2. Prepares Docker Buildx for multi-platform builds. |
| 170 | +3. Authenticates against Docker Hub using repository secrets. |
| 171 | +4. Generates OCI metadata, including links back to GitHub and Docker Hub. |
| 172 | +5. Builds the image and pushes the multi-arch `latest` tag. |
| 173 | + |
| 174 | +### π Required Secrets |
| 175 | + |
| 176 | +Add the following secrets in the GitHub repository settings before running the workflow: |
| 177 | + |
| 178 | +- `DOCKERHUB_USERNAME`: Docker Hub account name (for example `mgldvd`). |
| 179 | +- `DOCKERHUB_TOKEN`: Docker Hub access token with permission to push the repository. |
| 180 | + |
| 181 | +### βΆοΈ Triggering a Publish |
| 182 | + |
| 183 | +Push commits to the `deploy/hub` branch or run the workflow manually from the GitHub Actions tab to build and publish a new image version. |
| 184 | + |
| 185 | +## π€ Contributing |
| 186 | + |
| 187 | +Issues and pull requests are welcome. Please open a discussion in the GitHub repository if you plan substantial changes so proposals can be coordinated with the publishing workflow. |
0 commit comments