I wrote a Dockerfile
to make an image of my project:
FROM golang:alpine AS builder
WORKDIR /app
ADD go.mod .
COPY . .
RUN go build -o bot .
FROM alpine
WORKDIR /app
COPY --from=builder /app/bot /app/bot
COPY migration migration
COPY migrate.sh .
RUN chmod +x migrate.sh
CMD ["./bot"]
I need to copy migration
directory and migrate.sh
script to make migrations.
Then I wrote a docker-compose
file:
services:
postgres:
image: postgres:latest
container_name: postgres
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
ports:
- "${POSTGRES_PORT}:5432"
networks:
- bot-reminder
bot:
image: my_image
container_name: bot
restart: always
environment:
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PORT: ${POSTGRES_PORT}
TOKEN: ${TOKEN}
TIMEOUT: ${TIMEOUT}
MAX_MSG_SIZE: ${MAX_MSG_SIZE}
CHANNEL_ID: ${CHANNEL_ID}
LOG_LEVEL: ${LOG_LEVEL}
networks:
- bot-reminder
depends_on:
- postgres
command: ["./migrate.sh", "up"]
networks:
bot-reminder:
But when I run docker compose up -d
, the bot
container gives an error:
exec ./migrate.sh: no such file or directory
I run a command docker export bot > files.tar
. I saw all necessary files inside of files.tar
.
But why then container gives an error? Why it does not execute it?
I tried to write command ./migrate.sh up
in different ways: app/migrate.sh
, ./app/migrate.sh
, /app/migrate.sh
but it didn’t work.
I also added command ls
and it printed all necessary files.