-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ncurl: (7) Failed to connect to localhost port 3000: Connection refused #691
Comments
Please provide some relevant additional information such as your deploy.yml file, your entrypoint file, etc. |
FROM debian:bullseye-slim as base
ENV BUNDLER_VERSION="2.5.5" \
BUNDLE_DEPLOYMENT="1" \
BUNDLE_PATH="/usr/local/bundle" \
BUNDLE_WITHOUT="development" \
NODE_VERSION="20.11.0" \
NPM_VERSION="10.4.0" \
RAILS_ENV="production" \
RUBY_INSTALL_VERSION="0.9.3" \
RUBY_VERSION="3.3.0" \
YARN_VERSION="1.22.19"
ENV PATH="/opt/rubies/ruby-${RUBY_VERSION}/bin:/usr/local/node/bin:${PATH}"
RUN apt-get update && \
apt-get install -y \
autoconf \
build-essential \
curl \
fish \
git \
libpq-dev \
libvips \
pandoc \
pkg-config \
postgresql-client \
vim \
wget
RUN wget "https://github.com/postmodern/ruby-install/releases/download/v${RUBY_INSTALL_VERSION}/ruby-install-${RUBY_INSTALL_VERSION}.tar.gz" \
&& tar -xzvf "ruby-install-${RUBY_INSTALL_VERSION}.tar.gz" \
&& cd "ruby-install-${RUBY_INSTALL_VERSION}" \
&& make install
RUN ruby-install -p https://github.com/ruby/ruby/pull/9371.diff ruby "${RUBY_VERSION}"
WORKDIR /rails
FROM base as build
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
npm install -g "yarn@${YARN_VERSION}" && \
rm -rf /tmp/node-build-master
COPY Gemfile Gemfile.lock ./
RUN gem install bundler -v "${BUNDLER_VERSION}"
RUN bundle install && \
rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \
bundle exec bootsnap precompile --gemfile
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
RUN bundle exec bootsnap precompile app/ lib/
RUN HOST=example.com \
BASE_URL=https://example.com \
RAILS_MASTER_KEY_DUMMY=1 \
SECRET_KEY_BASE_DUMMY=1 \
./bin/rails assets:precompile
FROM base
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails
RUN useradd rails --create-home --shell /bin/bash && \
chown -R rails:rails db log storage tmp
USER rails:rails
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
EXPOSE 3000
CMD ["./bin/rails", "server"]
service: code
image: dorianmariecom/code
builder:
remote:
arch: amd64
ssh: root@45.55.196.152
servers:
web:
hosts:
- 45.55.196.152
labels:
traefik.http.routers.code.rule: Host(`code.dorianmarie.com`)
traefik.http.routers.code_secure.entrypoints: websecure
traefik.http.routers.code_secure.rule: Host(`code.dorianmarie.com`)
traefik.http.routers.code_secure.tls.certresolver: letsencrypt
traefik.http.routers.code_secure.tls: true
registry:
username:
- KAMAL_REGISTRY_USERNAME
password:
- KAMAL_REGISTRY_PASSWORD
env:
clear:
HOST: code.dorianmarie.com
BASE_URL: https://code.dorianmarie.com
secret:
- RAILS_MASTER_KEY
- POSTGRES_PASSWORD
traefik:
options:
publish:
- "443:443"
volume:
- "/letsencrypt/acme.json:/letsencrypt/acme.json"
args:
entryPoints.web.address: ":80"
entryPoints.websecure.address: ":443"
entryPoints.web.http.redirections.entryPoint.to: websecure
entryPoints.web.http.redirections.entryPoint.scheme: https
entryPoints.web.http.redirections.entrypoint.permanent: true
certificatesResolvers.letsencrypt.acme.email: "dorian@dorianmarie.com"
certificatesResolvers.letsencrypt.acme.storage: "/letsencrypt/acme.json"
certificatesResolvers.letsencrypt.acme.httpchallenge: true
certificatesResolvers.letsencrypt.acme.httpchallenge.entrypoint: web
accessories:
db:
image: postgres:16.1
host: 45.55.196.152
port: 5432
env:
clear:
POSTGRES_USER: code
POSTGRES_DB: code_production
secret:
- POSTGRES_PASSWORD
directories:
- data:/var/lib/postgresql/data
#!/bin/bash -e
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
./bin/rails db:prepare
fi
exec "${@}" Hope that helps |
Does your application respond to Another thing that helped figure out a similar issue was to ssh into my app instance and execute the Docker command that Kamal executes directly and then follow the logs output, in your example: |
I'm getting:
I don't understand, I have my db accessory defined |
@dorianmariecom You can't use the socket( Take a look at your database.yml, your host will need to point to 45.55.196.152. |
@dorianmariecom I see multiple issues in your configuration. First, like @nickhammond mentioned you are using a single server setup - which requires additional configuration. You have to update your database credentials to point to the SERVER_IP with the POSTGRES_PORT. Or, which I recommend, create a docker network and assign all containers to that network. With this approach you still have to update the database credentials but would use the container name instead of the SERVER_IP. Second (next upcoming issue), you are using rails user in your dockerfile but are deploying / setting up containers & volumes with root user, which will result in rails not being able to setup/access the storage because of user uid mismatch on host and container. Anyway I encourage you to create a new user on your host as containerized deployment processes do not need any root permissions at all. This new user needs to have the same uid as your rails user defined in your dockerfile. |
@nickhammond By using the right user (code, not root, not rails) I'm able to connect to the database, thanks a lot <3 |
deploy successful :), now onto the second point by @n1xn |
I'm really not sure how to do that |
Maybe ChatGPT can help you out... Let's assume you will ignore creating a new user on the host - you would have to do the following:
|
Actually I just use root for everything now and it's fine |
@dorianmariecom How do you resolve the issue? |
I've got a similar issue. My app container doesn't get started with a port mapping:
So the container starts but it can't be accessed via http. My deploy yaml is:
|
I'm getting unhealthy containers and I can't seem to fix it, any help?
The text was updated successfully, but these errors were encountered: