labnotes

Using python venv in docker

ruby and python, sitting in a tree

tags
ruby
python
docker

Contents

I was building a sinatra app and needed to throw in some python binaries. Here's a Dockerfile that handles both Gemfile and requirements.txt.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
    ARG RUBY_VERSION=3.3.4
    FROM ruby:$RUBY_VERSION-slim as base

    RUN apt-get update -qq && \
        apt-get install --no-install-recommends -y build-essential curl sqlite3

    RUN apt-get install -y python3 python3-pip python3.11-venv

    RUN gem update --system --no-document && \
        bundle config set --local without development

    # Rack app lives here
    WORKDIR /app

    ENV VIRTUAL_ENV=/opt/venv
    RUN python3 -m venv $VIRTUAL_ENV
    ENV PATH="$VIRTUAL_ENV/bin:$PATH"

    COPY requirements.txt .
    RUN /opt/venv/bin/pip install -r requirements.txt

     # Install application gems
    COPY Gemfile* .
    RUN bundle install --without development

    RUN useradd ruby --home /app --shell /bin/bash
    RUN chown -R ruby:ruby /app

    USER ruby:ruby
    ENV APP_ENV=production
    ENV PATH="$VIRTUAL_ENV/bin:$PATH"

    # Copy application code
    COPY --chown=ruby:ruby . .

    # Start the server
    EXPOSE 3000
      CMD ["bundle", "exec", "rackup", "--host", "0.0.0.0", "--port", "3000"]

Previously

labnotes

degit to template projects

nice way to clone

tags
git

Next

howto

Command line parsing in typescript

its no thor but its ok

tags
typescript
cli
cmd-ts