Difference between Dockerfile and Docker-Compose

Asked

Viewed 62 times

0

I’m having doubts about the images.

I understood the part that Dockerfile creates the image and that Docker-Compose manages the images that will be used in that application but why I have to create 1 images in dockerfile and download the others by Docker-Compose as for example:

Dockerfile

FROM node-alphine

Docker-Compose

services:
  pgsql
    image:postgres

I would have to create the image of postgres in Dockerfile ?

  • 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

  • 2

1 answer

0

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"]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.