I got this error suddenly.
Before getting this error I could connect.
$ curl localhost:3000
curl: (7) Failed to connect to localhost port 3000: Connection refused
My environments are below.
OS:macOS Sierra 10.12.6
Docker version 18.06.1-ce, build e68fc7a
docker-compose.yml
version: "3"
services:
web:
build: web
ports:
- "3000:3000"
environment:
- "DATABASE_HOST=db"
- "DATABASE_PORT=5432"
- "DATABASE_USER=********"
- "DATABASE_PASSWORD=********"
links:
- db
volumes:
- "./app:/app" #共有フォルダの設定
stdin_open: true
db:
image: postgres:10.1
ports:
- "5432:5432"
environment:
- "POSTGRES_USER=********"
- "POSTGRES_PASSWORD=********"
Dockerfile
FROM ruby:2.5.0
RUN apt-get update && apt-get install -y build-essential libpq-dev postgresql-client
RUN gem install rails
RUN mkdir /app
WORKDIR /app
If you have some suggestion to solve this please tell me.
Thanks.
you should specify your command for running application like: bundle exec rails s -p 3000 -b '0.0.0.0' which run your server on port 3000 and bind it to local network 0.0.0.0.
so you should write it in your Dockerfile in the last line:
RUN bundle exec rails s -p 3000 -b '0.0.0.0'
Related
When i try to access my lambda endpoint from outside i receive this error:
curl -XPOST 127.0.0.1:3000/create-loan
Recv failure: Connection reset by peer
But inside docker the endpoint work, the port 3000 does not working from outside.
Any help?
Name Command State Ports
billing_db_1 docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
billing_lambda_1 /usr/local/bin/sam local s ... Up 0.0.0.0:3000->3000/tcp
docker-compose.yml
version: '3'
services:
lambda:
build: .
volumes:
- ./:/app
- /var/run/docker.sock:/var/run/docker.sock
depends_on:
- db
environment:
- PYTHONPATH=${PWD}/billing
ports:
- "3001:3000"
db:
image: postgres
volumes:
- db-data:/var/lib/postgresql/data
ports:
- "5432:5432"
environment:
- POSTGRES_USER=${BILLING_USER}
- POSTGRES_PASSWORD=${BILLING_PASSWORD}
- POSTGRES_DB=${BILLING_DB}
- POSTGRES_HOST=${BILLING_HOST}
volumes:
db-data:
driver: local
My DockerFile:
FROM python:3.7
RUN pip3 install aws-sam-cli
EXPOSE 3000
ENTRYPOINT ["/usr/local/bin/sam"]
RUN apt-get install curl
RUN pip3 install pipenv
WORKDIR /app
RUN pipenv install --dev
CMD ["local", "start-api"]
Solved
CMD ["local","start-api","--host","0.0.0.0"]
By the compose file you've exposed the port 3001
ports:
- "3001:3000"
But connecting to 3000
curl -XPOST 127.0.0.1:3000/create-loan
I am setting up docker-compose for an existing Ruby on Rails project. I am using docker-compose version 1.23.1, build b02f1306 and Docker version 18.09.0, build 4d60db4
When I am trying to start my containers for development using docker-compose up --build my web and worker containers are exiting with code 10. When I /bin/bash into them the /web_gen folder only contains a /tmp/db inside of that and postgres files inside of that.
I can get the containers working by changing the volumes to - /web_gen but then the volumes will not hot reload.
My docker-compose.yml
version: '3'
services:
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/web_gen
ports:
- "3000:3000"
depends_on:
- db
- redis
db:
image: 'postgres:9.4.5'
volumes:
- ./tmp/db:/var/lib/postgresql/data
redis:
image: 'bitnami/redis:latest'
environment:
- ALLOW_EMPTY_PASSWORD=yes
worker:
build: .
command: bundle exec sidekiq -c 1
volumes:
- .:/web_gen
depends_on:
- redis
Dockerfile
FROM ruby:2.3.3
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /web_gen
WORKDIR /web_gen
COPY Gemfile /web_gen/Gemfile
COPY Gemfile.lock /web_gen/Gemfile.lock
RUN bundle install
COPY . /web_gen
I am following this tutorial from docker Docker Rails and I have created a folder and added this code below in my docker file.
FROM ruby:2.5
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
COPY . /myapp
And my docker compose file code is:
version: '3'
services:
db:
image: postgres
volumes:
- .data:/var/lib/postgresql/data
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
I am following tutorial when I am running docker compose up I can just see this error:
Could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
What is wrong here I don't know how to inspect and detect error how to fix this.
You need environment variables within your web container so that it knows how to connect to the db container.
version: '3'
services:
db:
image: postgres
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=
volumes:
- ./data:/var/lib/postgresql/data
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
environment:
- PGHOST=db
- PGUSER=postgres
volumes:
- .:/myapp
ports:
- "3000:3000"
depends_on:
- db
Please go to your database.yml and add host set to db , then username and password and run the command again.
I am using docker. Whenever my application is trying to read or write the cache it is getting following error :
Cache read: send_otp_request_count_3
Dalli::Server#connect 127.0.0.1:11211
127.0.0.1:11211 failed (count: 0) Errno::ECONNREFUSED:
Connection refused - connect(2) for "127.0.0.1" port 11211
DalliError: No server available
My Gemfile has:
gem 'dalli'
My Dockerfile is:
FROM ruby:2.3.6
RUN mkdir -p /railsapp
WORKDIR /railsapp
RUN apt-get update && apt-get install -y nodejs --no-install-recommends
RUN apt-get update && apt-get install -y mysql-client --no-install-recommends
COPY Gemfile /railsapp/
COPY Gemfile.lock /railsapp/
RUN bundle install
COPY . /railsapp
EXPOSE 3000
CMD ["rails", "server", "-b", "0.0.0.0"]
My docker-compose.yml file is:
version: '3.3'
services:
cache:
image: memcached:1.4-alpine
mysql:
image: mysql
restart: always
ports:
- "3002:3002"
volumes:
- /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=dev
web:
container_name: party_manager
build:
context: .
dockerfile: Dockerfile
environment:
- RAILS_ENV=development
ports:
- '3000:3000'
volumes:
- .:/railsapp
links:
- mysql
I have also also installed the memchaced in container shell through
docker exec -it 499e3d1efe44 bash
**499e3d1efe44 is my container id.
Then install the gem with command: gem install memcached
By default Compose sets up a single network for your app. Each
container for a service joins the default network and is both
reachable by other containers on that network, and discoverable by
them at a hostname identical to the container name.
So according to your docker-compose.yaml file you can access you cache container on cache:112111 from web container.
I am trying to run simple Rails app using docker.
Source code taken from data container 'app'. The 'app' data container also used by nginx to server precompiled assets and static files.
But no precompiled assets found after running 'bundle exec rake assets:precompile'.
I am using docker on Mac OS X with VirtualBox (Docker version 1.10.1, build 9e83765).
docker-compose.yml
version: '2'
services:
web:
build: .
command: bundle exec puma
env_file: .env
environment:
- RACK_ENV=production
- RAILS_ENV=production
volumes_from:
- app
ports:
- "3000:3000"
links:
- db
nginx:
image: nginx
ports:
- "80:80"
volumes_from:
- app
volumes:
- /app/public:/usr/share/nginx/html:ro
- /app/config/deploy/nginx.conf:/etc/nginx/conf.d/default.conf
db:
image: postgres
env_file: .env
volumes_from:
- data
app:
image: busybox
volumes:
- /myapp/app:/app:rw
data:
image: busybox
volumes:
- /myapp/data:/var/lib/postgresql/data
Dockerfile
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR /app
ADD . /app
RUN gem install bundler && bundle install --jobs 20 --retry 5 --without development test && rake assets:precompile
VOLUME /app/public
I tried also without 'VOLUME /app/public'
Please advice what can be the issue.
Thanks.
Volumes are not mounted during a docker build.
Run the rake assets:precompile task post build from a container with the volume mounted.
Also, since Docker 1.9, you no longer require a "data volume container". Volumes can exist on their own.
$ docker volume create --name=app_public
$ docker run -v app_public:/public busybox sh -c "echo hello > /public/file.txt"
$ docker run -v app_public:/public busybox sh -c "cat /public/file.txt"