This repository is very much a work in progress. Feel free to try some of these out and/or contribute to this repo. I am far from an expert at building Docker images so if you know more than me I'd love to be schooled.
This file uses the python:3.9-slim image:
- It first creates a python virtual environment /ledfx/venv
- "activate" the python venv by adding it to the
PATH
- Install compile and run dependencies with
apt-get
- Install ledfx-dev from
pip
- Purge compile dependencies with
apt-get
,clean
andautoremove
- Add ledfx user and create a home folder
- Set
WORKDIR
to ledfx home directory and changeUSER
to ledfx EXPOSE
ports 8888 and 5353- Launch ledfx
How to use: docker build -t ledfx .
This file uses the python:3.7-slim image:
-
Create a "compile-image"
- Set
WORKDIR
to /ledfx - Install compile dependencies with
apt-get
- Clone ledfx dev branch into /ledfx using
git clone
- cd to /ledfx/frontend
- Install
yarn
and build the frontend - cd to /ledfx
- Create a python venv /ledfx/venv and "activate" it by adding it to the
PATH
- Install ledfx-dev from source using
pip
- Set
-
Create a "build-image"
COPY
/ledfx/venv from "compile-image" to current image- Activate the venv by adding it to the
PATH
- Install run dependencies with
apt-get
- Add ledfx user and create a home folder
- Set
WORKDIR
to ledfx home directory and changeUSER
to ledfx EXPOSE
ports 8888 and 5353- Launch ledfx
How to use: docker build -t ledfx-2stage -f Dockerfile-2stage-1 .
This file uses docker's multi-stage build technique to speed up the build process using the cache and cut down the overall size of the final image.
While all 4 images will be built initially, we can significantly cut down the build times by using the cached images that won't change regularly. Docker will use the cache up until the point in the Dockerfile that it detects a change. Any lines after that change will be build from scratch.
By creating the venv and compile images in the beginning of the Dockerfile, we can be fairly certain that these dependencies won't change regularly. This cuts down the time required to build by skipping the dependency installation process.
-
Create "venv-image"
- Create a python venv /ledfx/venv and "activate" it by adding it to the
PATH
- Install compile and run dependencies with
apt-get
- Create a python venv /ledfx/venv and "activate" it by adding it to the
-
Create "compile-image" from "venv-image"
- Install build dependencies with
apt-get
- Install build dependencies with
-
Create "build-image" from "compile-image"
COPY
/ledfx/venv from "venv-image" to current image- Activate the venv by adding it to the
PATH
- Set
WORKDIR
to /ledfx-git - Clone ledfx dev branch into /ledfx-git using
git clone
cd
to /ledfx/frontend- Install
yarn
and build the frontend cd
to /ledfx- Create a python venv /ledfx/venv and "activate" it by adding it to the
PATH
- Install ledfx-dev from source using
pip
-
Create "dist-image" from "venv-image"
COPY
/ledfx/venv from "build-image" to current image- Activate the venv by adding it to the
PATH
- Remove all lists from /var/lib/apt/lists/
- Add ledfx user and create a home folder
- Set
WORKDIR
to ledfx home directory and changeUSER
to ledfx EXPOSE
ports 8888 and 5353- Launch ledfx
How to use: docker build -t ledfx-4stage -f Dockerfile-4stage .
These files take a similar approach to Dockerfile-4stage. They differ in the fact that they use 3 independent Dockerfile's to achieve the same results. I'm not sure if this is significant, but I was learning how to create Dockerfile's when I wrote these so I decided to try it out.
-
Dockerfile.venv
- Create "venv-image" from python:3.9-slim
- Create a python venv /ledfx/venv and "activate" it by adding it to the
PATH
- Install run dependencies with
apt-get
How to use: docker build -t ledfx-venv -f Dockerfile.venv .
-
Dockerfile.compile
- Create "compile-image" from "venv-image" named ledfx-venv
- Activate the venv by adding it to the
PATH
- Install build dependencies with
apt-get
- Install ledfx-dev with
pip
How to use: docker build -t ledfx-compile -f Dockerfile.compile .
-
Dockerfile.build
- Create build image from "venv-image" named ledfx/ledfx-venv
COPY
/ledfx/venv from "compile-image" named ledfx/ledfx-compile- Remove all lists from /var/lib/apt/lists/
- Add ledfx user and create a home folder
- Set
WORKDIR
to ledfx home directory and changeUSER
to ledfx EXPOSE
ports 8888 and 5353- Launch ledfx
How to use: docker build -t ledfx-build -f Dockerfile.build .