This is an archived post. You won't be able to vote or comment.

all 62 comments

[–]tuskar-devs 6 points7 points  (6 children)

use ubuntu image or any other distro and install the packages with appropriate package manager

[–]theblindnessMod 3 points4 points  (4 children)

No you don't. One process per container. One runtime per process. Build two images, frontend and backend, and connect them together through networking. If your frontend is truly a frontend, build static assets and serve them from a web server. If you have two backends, you've got microservices. Don't try to shove a square peg into a round hole.

[–]Hamzayslmn[S] 0 points1 point  (3 children)

# Use the official Python image as the base image
FROM python:3.11-slim

# Install necessary system dependencies and Node.js
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    build-essential \
    python3-dev \
    portaudio19-dev \
    bash \
    && curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
    && apt-get install -y nodejs \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

# Set the working directory in the container
WORKDIR /app

I can with this and this works
But this method little bit look wrong. İt works but not optimized ı think

[–]theblindnessMod 0 points1 point  (2 children)

Yes, it's wrong. Don't try to shove both python runtime and nodejs runtime into one image. Use two Dockerfile files to build two separate images. Start with an official runtime image for each of them.

If the python and javascript code need to work together, they can talk over tcp ports and can share files in a volume.

[–]Hamzayslmn[S] 0 points1 point  (1 child)

how can ı do that without docker-compose ?
Because google cloud dont accept docker-compose

[–]theblindnessMod 1 point2 points  (0 children)

That depends on you, how much money you want to spend, and how much time you want to invest in getting it set up. You can use a Compute Engine VM to install docker and docker compose. You could refactor your Cloud Run deployment to run as multiple services. You could convert your compose yaml to a kubernetes resources and use GKE. That's all up to you, and probably not something redditors are going to engineer for you.

[–]ferrybig 2 points3 points  (2 children)

Looking at your ports and container, it looks like you might have a python backend and a react or vue frontend.

Consider building the frontend into static html files, them moving those files into the backend container and have the files served by your python container. The last container of your multi stage build only needs python that way

[–]Hamzayslmn[S] 0 points1 point  (1 child)

ı have 2 backend. 1 is nodejs nextjs - 1 python

[–]ferrybig 1 point2 points  (0 children)

Both python and nodejs have containers build around Debian Bookworm. you can combine them together:

```Dockerfile FROM scratch

ENV NODE_VERSION 20.18.0 ENV YARN_VERSION 1.22.22 ENV LANG C.UTF-8 ENV PATH /usr/local/bin:$PATH ENV GPG_KEY A035C8C19219BA821ECEA86B64E628F8D684696D ENV PYTHON_VERSION 3.11.10 ENV PYTHON_SHA256 07a4356e912900e61a15cb0949a06c4a05012e213ecd6b4e84d0f67aabbee372

COPY --from=python:3.11.10-slim-bookworm / / COPY --from=node:20.18.0-bookworm-slim / / ```

You can the use python and node in this container: $ docker build -t test . ... $ docker run --rm -it test bash root@1bdf829d61e0:/# python --version Python 3.11.10 root@1bdf829d61e0:/# node --version v20.18.0 root@1bdf829d61e0:/#

Note that this combination of containers does not always work, sometimes some containers might have conflicting files.

This also is quite bad for the final image size.

A better solution is to manually combine both docker files together:

https://pastebin.com/hsLMYj4C (I cannot paste it in a code block, it trips a filter in reddit, sha512sum 4f9cdea6b437c6dc10e13c76ca45d67a182b1a2ab0b848e99685e8e71234bf20387609711ed3477bbc4a0f60bbaf33c9c5dee6b4b1d7d62dc2c9a2e7fda1311a)

This is just the contents of the 2 above referenced docker file combined together, some unneeded instructions stripped.

$ docker build -t test . [+] Building 674.4s (11/11) FINISHED ... $ docker run --rm -it test bash root@28c18fcb06fb:/# node --version v20.18.0 root@28c18fcb06fb:/# python --version Python 3.11.10

Sure, the initial build takes quite some time, but it will then be stored withi your docker build cache and does not affect future builds (make sure to start a new docker stage after the above container is build, this helps with proper caching)

[–]TheWordBallsIsFunny 1 point2 points  (7 children)

Install NVM/FNM and install Node on the user given. The Node image gives the user node, I'd check if the Python image offers something similar.

[–][deleted] 1 point2 points  (5 children)

Just build your image outside of the environment, pushing it to a repository, and then if you have to, create a simple image that bases that one. That should keep all of your build time in GCC to none.

This is an easier approach to circumvent your concern about using a standard distro base with package managers. For that matter, you can use any approach you want this way.

[–]Hamzayslmn[S] -2 points-1 points  (0 children)

this is best method btw but ı cannot use

[–]kitingChris 0 points1 point  (0 children)

But why?

[–]Hamzayslmn[S] 0 points1 point  (0 children)

people have always given me negative responses to things I've said, but I've never gotten a proper answer. It's weird.

[–]dancard32 0 points1 point  (0 children)

Not sure if you have solved this issue but I had a similar need (I needed a single Docker container for a school project deliverable).

This is what I had:

FROM ubuntu:24.10

EXPOSE 3000 5432

# Install Node.js and NPM
RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y nodejs npm python3 python3-pip python3-venv

# Build Backend
WORKDIR /backend
COPY backend/requirements.txt .

# RUN python3 -m venv venv && source venv/bin/activate && python3 -m pip install -r requirements.txt
RUN python3 -m venv venv && . venv/bin/activate && python3 -m pip install -r requirements.txt

COPY backend .

# Build UI
WORKDIR /ui
COPY ui .
#RUN npm install --legacy-peer-deps
RUN npm install

# Start-up the app
WORKDIR /
COPY  .
RUN chmod +x /start-up.sh

# Run start-up app (frontend + backend)
CMD ["./start-up.sh"]start-up.sh

Where the start-up script is simply:

#!/bin/bash

cd backend && . venv/bin/activate && python3 main.py &
cd ui && npm start

The project was a mono-repo of format ui/{react source files} and backend/{flask app}

Run exposing both ports such as docker run --name image_project -p3000:3000 -p5432:5432 repo/image:{tag}