Answer the question
In order to leave comments, you need to log in
How to write a Docker file for the Front+Back+DB bundle?
Hello, I have a project consisting of Front (JS+React) + Back (Go binary + config files) + DB (PostgreSQL).
Is it possible to stuff it all into a container and tie it together?
If so, are there any Dockerfile examples for such a bundle?
Do I need to integrate the PostgreSQL environment itself into this Docker file, or can only the database be integrated?
The backing binary runs on a specific port, will this binary be accessed by port from outside? I ask because if I launch several similar containers, will they conflict over ports? Or does each image need to be configured for a separate port?
Thanks to.
Answer the question
In order to leave comments, you need to log in
Everything is laid out in different containers.
Separate front, separate back, separate base, separate static, etc.
Access can be painted as you like, and yes, judging by your questions - this is for freelancing. ru question.
And hello to you.
Docker-compose to help you, for starters. It is rather dreary to operate with bare docker commands, and it is not required in real conditions.
Is it possible to stuff it all into a container and tie it together?
there is a project consisting of Front (JS + React) + Back (Go binary + config files) + DB (PostgreSQL)
Do I need to integrate the PostgreSQL environment itself into this Docker file, or can only the database be integrated?
The backing binary runs on a specific port, will this binary be accessed by port from outside?
I ask because if I run several similar containers, will they conflict over ports?
Or does each image need to be configured for a separate port?
# Тут берем официальный образ Golang для компиляции бинарника
# В нем есть все для сборки, за редким исключением
FROM golang:stretch as builder
# Устанавливаем рабочую директорию внутри образа сборки бинарника
WORKDIR /app
# Копируем содержимое директории с вашим проектом в образ для сборки
COPY . .
# Скачиваем зависимости
RUN go get -d -v
# Собираем бинарник в директорию /app/bin
RUN GOOS=linux GOARCH=amd64 go build -i -o bin/backend main.go
# А теперь берем минимальный образ для запуска бинарника
FROM scratch
# Из образа для сборки, копируем готовый бинарник backend-а
COPY --from=builder /app/bin/backend /app/bin/backend
# Назначаем полученный бинарник точкой входа в контейнер
ENTRYPOINT ["/app/bin/backend"]
docker build -t backend:latest .
version: "3.7"
volumes:
database:
services:
# Postgres. Берем готовый официальный образ
database:
image: postgres:12-alpine
# Вот собственно тут и указывается, какие порты будут видны на вашей локали
ports:
- 5432:5432
# Там выше в volumes указывали набор volumes. Используем вольюм database, чтобы хранить БД
volumes:
- database:/var/lib/postgresql/data
restart: always
# Backend. Берем образ, что собрали выше
backend:
image: backend:latest
# В Dockerfile мы для гибкости не указывали порт backend-a. Укажем его тут.
expose:
- 8080
ports:
- 8080:8080
restart: always
# Frontend
frontend:
image: frontend:latest
expose:
- 80
ports:
- 80:80
restart: always
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question