Briefly, the Docker is container technology that allows you to place your applications in containers. A container is a standard software unit that packs the code and all its dependencies so that the application runs quickly and reliably from one computing environment to another. The Docker Compose allows you to build and run multiple containers on the same host.
I would have to create the image of postgres in Dockerfile ?
No, you don’t need to create a postgres image on Dockerfile. Just use an existing image. But you need to create an image for your application. For example:
.\Docker-Compose.yml
version: '3'
services:
postgres:
image: 'postgres:latest'
environment:
- POSTGRES_PASSWORD=postgres
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=postgres
- PGPASSWORD=postgres
- PGPORT=5432
.\Dockerfile.dev server
FROM node:14.14.0-alpine
WORKDIR "/app"
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "dev"]
usually when using a dockerfile it is expected that a local content is involved, most of the time the project itself, that you will generate the image, already in the case of postgres if you mark it there in the Compose it will try to download from the dockerhub, because it is an image that already exists
– Lucas Miranda
This answers your question? What’s the Difference Between Docker-Compose and Dockerfile?
– user131248