🌐
Reddit
reddit.com › r/docker › generic python docker container
r/docker on Reddit: Generic Python Docker Container
December 28, 2023 -

I thought today, about using Docker to setup virtual environments instead of using Pipenv because I'd like to learn Docker a bit. I watched some Python videos on it and all of these were setting up fastapi's which I don't need so I wanted to make a more generic dockerfile and yml file that I can come back to over and over again.

I created a dockerfile like below:

FROM python:3.12-slim

WORKDIR /code

COPY ./requirements.txt ./ RUN pip install --no-cache-dir -r requirements.txt

COPY ./src ./src

I created a docker-compose.yml file like below:

services:
  app: 
      build: . 
      container_name: py_env 
      volumes: 
          - .:/code

I ran the command docker compose up --build -d and had no errors, it said Container py_env Started but when doing docker ps there is no container and when using dev containers in VS code to try to attach to a running container it says there are no running containers to attach to.

What am I missing?

🌐
GitHub
github.com › mozilla › generic-python-docker
GitHub - mozilla/generic-python-docker: An example repo for a generic, dockerized Python project
February 4, 2021 - An example repo for a generic, dockerized Python project - mozilla/generic-python-docker
Starred by 17 users
Forked by 22 users
Languages   Python 39.9% | Makefile 24.9% | Dockerfile 19.1% | Shell 16.1% | Python 39.9% | Makefile 24.9% | Dockerfile 19.1% | Shell 16.1%
Discussions

The best way to use docker with Python for development environments
I will write the main points how we are do container-based environments with docker-compose. for each and separate site (both frontend and backend code) a separate repo with 1 docker-compose.yml which defines "nginx", "python", "redis", "node", "postgresql" services as separate containers (plus any other we need) and the codebase is mounted to these containers, we don't build new containers for every deploy. Now, since we use multiple sites on 1 machine and we'd like to run them in parallel at ports 80, 443, we have a separate repo with 1 docker-compose.yml that starts a Traefik reverse proxy witha "traefik" docker network. and each repo's docker-compose is set to connect to that "traefik" docker network, each site has a URL set with Traefik labels. For example we set for a repo that a "python" service URL is https://mysite1.com , then if you open the browser at that URL, Traefik automatically routes to that "python" service. Traefik also does built-in automatic Let's Encrypt SSL certificate generation. More info about that: https://doc.traefik.io/traefik/providers/docker/ for vscode there is a plugin called Dev Containers ( https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers ) these allow to attach to any running container in a new vscode window, and we can run debugger and code autocompletion there, since if you attach to a python container, you have a python environment installed. (Plus we use these also for python: https://marketplace.visualstudio.com/items?itemName=ms-python.python https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance , so we use DebugPy to debug python scripts inside that, we start the debugger at inside the container, and we can attach to it fine) for nodejs the same solution could be used. And I think you don't even need to attach to a node JS container as you can run on your computer commands that should execute inside a container like this: docker compose exec , for example: docker compose exec node npm run dev we start the dev environment with docker compose up -d (first for Traefik repo, and after Traefik runs, then again docker compose up -d for each and every site we need to work on), and stop it with docker compose down. Pretty straightforward and standard. note that docker compose down removes containers and volumes, so if you use a persistent database, then you need to define a volume for the db files, so the db will not be lost after docker compose down. If it is a small/medium site that doesn't need high availability and autoscaling, this Traefik with docker-compose solution also works fine for production. The docker-compose alternatives for creating easier dev environments are Lando or DDEV but there's less documentation about those for Python projects, and they are not suitable for production but they are easier to use than docker compose. For example, they do this Traefik proxy setup by themselves, you can create scriptable commands, so you don't need to write the whole command every time like "docker compose exec python python manage.py runserver 0.0.0.0:80" but with a customly defined "lando runserver" as a simple example. More on reddit.com
🌐 r/docker
6
3
March 5, 2024
Generic Python Docker Container
you can't just create an image and run it, you have to provide a action that triggers the container. for example use CMD [ "python", "./my_script.py" ] More on reddit.com
🌐 r/docker
4
1
December 28, 2023
[Tutorial] How to run Julia inside a Docker container and connect it to Juno IDE
Hi, newb wannabe programmer here, sorry for the stupid questions and scenario about to follow. I recently got my mgmt to agree to let me experiment with Julia on my work computer (corporate windows environment). The short term goal is to come up with some analytic tools around the work that we already do. The long term goal is to try to convince senior mgmt to let us rewrite (some of) the company’s heavy computational systems with Julia. I will only have three days of admin access to install what I need to get up and running. I am already planning on installing the Juno IDE, as well as versions 1.1 and 0.7 (to be able to update any packages that are still on 0.6). My question is this: do I need Docker? I’m not sure what it even does exactly. My initial need is small scale — just a write a few scripts for analysis and visualization. My long term goal, which isn’t all that feasible, will require being able to deploy code to production. It seems that’s what Docker would be good for, but I am no where near close to anything production (and may never be). So does it make sense for me to install it? Would I get any benefit out of it even if my purposes remain small scale? More on reddit.com
🌐 r/Julia
11
21
May 8, 2019
How to install and use Docker on Synology - guide for beginners

I'm having a little trouble understanding what Docker does and what the point of it is. Can you illuminate?

More on reddit.com
🌐 r/synology
7
12
July 27, 2015
People also ask

How to use Docker with Python?
To build a Docker image, you need to create a Dockerfile. It is a plain text file with instructions and arguments. When Dockerfile is ready, use docker build command to build a new image. After that, you can create containers and run them (using docker run command) from the image.
🌐
djangostars.com
djangostars.com › home › docker tutorial: using docker with python
Python Docker Tutorial: How to Use Docker with Python | Django Stars
What is Docker in Python?
Docker is an open-source tool that automates the deployment of an application inside a software container. When you develop an application, you need to provide your code along with all possible dependencies like libraries, the web server, databases, etc. You may end up in a situation when the application is working on your computer, but won’t even start on the staging server, or the dev or QA’s machine. This challenge can be addressed by isolating the app to make it independent of the system.
🌐
djangostars.com
djangostars.com › home › docker tutorial: using docker with python
Python Docker Tutorial: How to Use Docker with Python | Django Stars
What are the best practices of using Docker in Python?
Include only necessary context – use a .dockerignore file (like .gitignore in git). Avoid installing unnecessary packages – it will consume extra disk space. Use cache - add context that changes a lot at the end of Dockerfile to utilize Docker cache effectively. Be careful with volumes - because volumes are persistent, the next container will use data from the volume created by the previous container. Use environment variables (in RUN, EXPOSE, VOLUME) - it will make your Dockerfile more flexible.
🌐
djangostars.com
djangostars.com › home › docker tutorial: using docker with python
Python Docker Tutorial: How to Use Docker with Python | Django Stars
🌐
Docker
docs.docker.com › guides › python › containerize your app
Containerize your app | Docker Docs
RUN --mount=type=cache,target=/root/.cache/pip \ --mount=type=bind,source=requirements.txt,target=requirements.txt \ python -m pip install -r requirements.txt # Switch to the non-privileged user to run the application.
🌐
Django Stars
djangostars.com › home › docker tutorial: using docker with python
Python Docker Tutorial: How to Use Docker with Python | Django Stars
September 11, 2025 - Full guide about uses of Docker with Python. Our team created this tutorial to share the passion and knowledge of Docker enthusiasts.
🌐
Visual Studio Code
code.visualstudio.com › docs › containers › quickstart-python
Python in a container
November 3, 2021 - Build, run, and verify the functionality of a Django, Flask, or General Python app. Debug the app running in a container. Install Docker on your machine and add it to the system path.
🌐
Real Python
realpython.com › tutorials › docker
Python Docker Tutorials – Real Python
Learn how to use docker compose for local development, set up volumes and networks, cache builds for speed, and push images to Docker Hub. Explore patterns for testing, multi stage builds, slim images, and security basics like non root users ...
🌐
Docker
docker.com › blog › containerized-python-development-part-1
Containerized Python Development - Part 1 | Docker
May 24, 2024 - Sending build context to Docker daemon 6.144kB Step 1/6 : FROM python:3.8 3.8.3-alpine: Pulling from library/python … Status: Downloaded newer image for python:3.8.3-alpine ---> 8ecf5a48c789 Step 2/6 : WORKDIR /code ---> Running in 9313cd5d834d Removing intermediate container 9313cd5d834d ---> c852f099c2f9 Step 3/6 : COPY requirements.txt .
Find elsewhere
🌐
GitHub
github.com › mozilla › generic-python-docker › blob › master › Dockerfile
generic-python-docker/Dockerfile at master · mozilla/generic-python-docker
February 4, 2021 - An example repo for a generic, dockerized Python project - mozilla/generic-python-docker
Author   mozilla
🌐
Docker
docker.com › blog › how-to-dockerize-your-python-applications
How to “Dockerize” Your Python Applications | Docker
If you’re seeking a blueprint for deploying Python apps within Docker containers, look no further! Patrick uses many mechanisms, libraries, and commands that you might leverage yourself while developing applications. He also covers some Docker basics—making it much easier to incorporate Docker without expert knowledge.
Published   November 6, 2024
🌐
Docker Docs
docs.docker.com › reference › samples › python samples
Python samples | Docker Docs
Docker Samples: A collection of over 30 repositories that offer sample containerized demo applications, tutorials, and labs.
🌐
University of Manchester
research-it.manchester.ac.uk › news › 2025 › 06 › 19 › getting-started-with-docker
Getting Started with Docker: Python “Hello World” Example
A Dockerfile is a text file containing instructions to build a Docker image. Create a file named Dockerfile (this is the standard convention): # Dockerfile # Use an official lightweight Python image FROM python:3.12-slim # Set the working directory inside the container WORKDIR /app # Copy the ...
🌐
Earthly
earthly.dev › blog › python-docker
Running Python on Docker - Earthly Blog
July 24, 2023 - It is cost-effective, efficient for CI/CD deployments, scalable, and easy to use, making it a good choice for your Python applications. This tutorial will show you how to build a Docker container for running a simple Python application.
🌐
GeeksforGeeks
geeksforgeeks.org › python › setting-up-docker-for-python-projects-a-step-by-step-guide
Setting Up Docker for Python Projects: A Step-by-Step Guide - GeeksforGeeks
July 23, 2025 - Follow the installation instructions ... create a simple Python project locally and add Python Files: Create a simple Python script inside your project directory....
🌐
Python for Data Science
python4data.science › en › latest › productive › git › advanced › gitlab › ci-cd › docker.html
Building Docker containers - Python for Data Science
FROM your-docker/build-image as build ARG PY RUN --mount=type=cache,target=/root/.cache \ set -ex \ && virtualenv --python $PY /app … FROM your-docker/app-image … RUN set -ex \ && apt-get update -qy \ && apt-get install -qy \ -o ...
🌐
Docker
docker-py.readthedocs.io › en › stable
Docker SDK for Python — Docker SDK for Python 7.1.0 documentation
To talk to a Docker daemon, you first need to instantiate a client. You can use from_env() to connect using the default socket or the configuration in your environment: ... >>> client.containers.list() [<Container '45e6d2de7c54'>, <Container 'db18e4f20eaa'>, ...] >>> container = client.con...
🌐
Docker
docs.docker.com › guides › python › develop your app
Use containers for Python development
In this section, you took a look at setting up your Compose file to add a local database and persist data. You also learned how to use Compose Watch to automatically rebuild and run your container when you update your code. ... In the next section, you'll learn how you can set up linting, formatting and type checking to follow the best practices in python apps.
🌐
Tutorial Works
tutorialworks.com › python-develop-container
How I Created a Python Development Environment with Docker - Tutorial Works
December 20, 2024 - My starting point is the python:3.9-alpine image on Docker Hub. (It’s a “Docker Official” image on Docker Hub, so I have, uhhhhh, some confidence about its quality and security. Better to use this than an unofficial one.) ... Then I change the working directory to /usr/src/app. This tells Docker where to run the remaining commands. So I add this command: ... Next, I copy the requirements.txt file that I just wrote, and put it in the container.
🌐
Runnable
runnable.com › docker guides › python › dockerize your python application
Dockerize your Python Application | Runnable Docker Guides
July 19, 2016 - A guide to run your Python application in a Docker container with a Dockerfile and commands to build, run, and manage your Docker images.
🌐
Prefect
prefect.io › blog › dockerizing-python-applications
Dockerizing Your Python Applications: How To
April 19, 2024 - FROM python:3.12 RUN mkdir /usr/src/app COPY s3.py /usr/src/app COPY requirements.txt /usr/src/app WORKDIR /usr/src/app RUN pip install -r requirements.txt CMD ["python", "./s3.py"] Here’s what each line of this Dockerfile is doing: FROM: Defines the base image your container will use - in this case, the standard Python 3.12 image from the Docker Hub repository, which runs on a stripped-down verison of Linux that contains both Python and pip.