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:
- .:/codeI 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?
Top answer 1 of 3
2
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" ]
2 of 3
1
Maybe just add the following: entrypoint: bash stdin_open: true tty: true Run with docker compose up --build -d And docker compose exec app bash to ssh into it.
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%
I created a 40-minute tutorial that will explain everything you need to Containerize your Python applications using Docker!
Well done, detailed but not boring (even for the parts that I already knew). Kudos also for scaling up the font in your editor to make it easy to read. I don't understand why not everybody does it. More on reddit.com
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
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
[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
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
Videos
18:47
This Is How You Write an Efficient Python Dockerfile - YouTube
05:38
How to Run a Simple Python Program in a Docker Container - YouTube
20:51
Containerize Python Applications with Docker - YouTube
26:08
How to containerize Python applications with Docker - YouTube
11:44
How to Build a Docker Container with Python - YouTube
05:20
Docker Python Tutorial #2: First Docker Container - YouTube
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 .
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 ...
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...
Simplilearn
simplilearn.com › home › resources › software development › how to run a python script using docker: all you need to know
What Is Docker Python: How to Create and Run it? | Simplilearn
November 18, 2025 - Learn how Docker Python is used for automating the deployment of any application inside a software container. Read on to know how to create and run it.
Address 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
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.
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.