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 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.
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?
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.
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.
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.
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.
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.
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.
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 ...
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.
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 ...
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.
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....
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...
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.
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.
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.
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.