I’m doing a project that uses docker to create an app to send SMS via Twilio.
The project is build using Rails.
Right now, my docker-compose build 3 containers: Postgres, Prometheus and web-service.
Everything seems to work correctly, and I can access localhost:3000 (Web service to send SMS), localhost:9090 (prometheus, to see logs and stuff).
The issue is, my prometheus container is not accessing localhost:3000. I got 403 access denied, when trying on browser, inside prometheus app, and via internal prometheus docker shell – with wget pointing to localhost:3000
Dockerfile:
FROM ruby:2.7.5
# Update and install dependencies
RUN apt-get update -qq && apt-get install -y nodejs postgresql-client curl
# Install Yarn
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
&& apt-get update && apt-get install -y yarn
# Clean up
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Set the working directory inside the container
WORKDIR /app
# Add the `bin/` directory to the PATH
ENV PATH /app/bin:$PATH
# Copy the Gemfile and Gemfile.lock into the container
COPY Gemfile Gemfile.lock ./
# Install the correct version of Bundler
RUN gem install bundler:2.4.21
# Install gems
RUN bundle install --binstubs --jobs 20 --retry 5
# Copy the main application
COPY . /app
# Expose port 3000 to the outside
EXPOSE 3000
# Configure the main process to run when running the image
CMD ["sh", "-c", "bundle exec rails db:migrate && rails server -b '0.0.0.0'"]
docker-compose.yml
services:
db:
image: postgres
volumes:
- postgres_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: postgres
POSTGRES_DB: my_name_sms_service
ports:
- "5432:5432"
networks:
- skynet
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails db:migrate && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/app
ports:
- "3000:3000"
depends_on:
- db
environment:
DATABASE_URL: postgres://postgres:password@db/my_name_sms_service
TWILIO_ACCOUNT_SID: secret_key
TWILIO_AUTH_TOKEN: secret_key
TWILIO_PHONE_NUMBER: secret_phone
networks:
- skynet
prometheus:
image: prom/prometheus
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml
ports:
- "9090:9090"
networks:
- skynet
networks:
skynet:
volumes:
postgres_data:
Here’s how it appears:
enter image description here
Any clue?
Tried several different configurations for Dockerfile and docker-compose.
Created a network so all containers share it.
tried to add bypasses inside metrics_controller
:
protect_from_forgery with: :null_session
skip_before_action :verify_authenticity_token
RConsul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.