I am tryning to dockerize my rails application and I've already tried everything including restarting my postgres, restarting docker, removing all containers and images, removing networks, volumes, literally nuking everything relatied to docker but nothing helped.
When I do docker-compose up
I get an error
ERROR: for rails-rest-api_postgres_1 Cannot start service postgres: driver failed programming external connectivity on endpoint rails-rest-api_postgres_1 (6211b1f9b1dc688472760c389cc0684542c89cf8afee7dce7c90032f65c58511): Error starting userland proxy: listen tcp4 0.0.0.0:5432: bind: address already in use
lsof -i :5432
doesn't return anything
I've literally everything from this post https://github.com/docker/compose/issues/4126 and nothing helped.
This is my docker-compose.yml
version: '3.5'
services:
postgres:
image: postgres
environment:
POSTGRES_PASSWORD: postgres
ports:
- '5432:5432'
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- postgres
Dockerfile
FROM ruby:2.7.4-alpine as base
RUN echo "@edge http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
RUN apk update && apk upgrade && apk add build-base && apk --no-cache add \
tzdata \
bash \
git \
libstdc++ \
ca-certificates \
libffi-dev \
postgresql-dev \
postgresql-client \
linux-headers \
libpq \
openssh \
file \
libxml2-dev \
curl \
gmp-dev \
musl \
gcompat \
aws-cli@edge \
shared-mime-info \
libucontext-dev \
&& echo ‘gem: --no-document’ > /etc/gemrc
ARG IMAGE_TAG
ENV IMAGE_TAG=$IMAGE_TAG
RUN mkdir -p /app/vendor/gems
WORKDIR /app
COPY Gemfile /app/Gemfile
COPY Gemfile.lock /app/Gemfile.lock
RUN gem install bundler:2.2.24
RUN bundle config set --local deployment 'true'
RUN bundle config set --local without 'development test'
RUN bundle config --delete without
RUN bundle config --delete with
RUN bundle install
COPY . /app
RUN RAILS_ENV=staging \
DATABASE_URL=postgres:null \
SECRET_KEY_BASE=blah
ENTRYPOINT ["bundle", "exec"]
CMD ["rails", "server", "-b", "0.0.0.0"]
# Deploy Image
FROM base as deploy
RUN rm -rf /root/.ssh
# Dev Image
FROM base as dev
RUN bundle install --with development
RUN apk update && apk upgrade && apk --no-cache add \
curl-dev \
postgresql \
&& echo ‘gem: --no-document’ > /etc/gemrc
RUN rm -rf /root/.ssh
# CI Image
FROM base as ci
RUN apk update && apk upgrade && apk --no-cache add \
curl-dev \
postgresql \
&& echo ‘gem: --no-document’ > /etc/gemrc
RUN bundle install \
--with test \
--deployment
RUN rm -rf /root/.ssh
COPY config/database.ci.yml config/database.yml