Can't use binding.break in docker-compose - ruby-on-rails

I am running a Rails 7 app through docker-compose. When I try to use binding.break in the code, my attached terminal shows something like the following:
web | Started POST "/media_uploads" for 172.19.0.1 at 2022-07-02 20:57:26 +0000
web | Cannot render console from 172.19.0.1! Allowed networks: 127.0.0.0/127.255.255.255, ::1
web | [29, 38] in /web/config/initializers/rack_attack.rb
web | 29| end
web | 30|
web | 31| # Intended to prevent bulk upload overloading, but may have other consequences
web | 32| throttle('posts/ip', limit: 1, period: 1) do |req|
web | 33| if req.post?
web | => 34| binding.break
web | 35| req.ip
web | 36| end
web | 37| end
web | 38| ### Prevent Brute-Force Login Attacks ###
web | =>#0 block {|req=#<Rack::Attack::Request:0x00007fa9990ffc...|} in <class:Attack> at /web/config/initializers/rack_attack.rb:34
web | #1 Rack::Attack::Throttle#discriminator_for(request=#<Rack::Attack::Request:0x00007fa9990ffc...) at /usr/local/bundle/gems/rack-attack-6.6.1/lib/rack/attack/throttle.rb:53
web | # and 50 frames (use `bt' command for all frames)
but doesn't provide me with an input buffer to enter commands. I have to kill the process in order to do anything on the server. My docker-compose includes
tty: true
stdin_open: true
but it still doesn't work. Any ideas what to try?

EX: I have a docker-composer.yml
version: '3.3'
services:
db:
image: postgres
container_name: anywork_db
env_file:
- .db.env
ports:
- "5432:5432"
app:
image: anywork:latest
entrypoint:
- bash
- entrypoint.sh
build: .
container_name: anywork_app
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
volumes:
- .:/AnyWork
env_file:
- .app.env
links:
- db
ports:
- "3000:3000"
stdin_open: true
tty: true
depends_on:
- db
# command: puma
# sudo chown -R $USER:$USER .
If you debug, you must access container_name of app with docker attach container_name.
EX: docker attach anywork_name. It is work for you.

Related

docker-compose not recognizing prisma generate or changes

I have several docker images I'm trying combine using docker-compose.
My server image is failing with the following:
server_1 |
server_1 | To solve this problem, add the platform "linux-musl" to the "binaryTargets" attribute in the "generator" block in the "schema.prisma" file:
server_1 | generator client {
server_1 | provider = "prisma-client-js"
server_1 | binaryTargets = ["native"]
server_1 | }
server_1 |
server_1 | Then run "prisma generate" for your changes to take effect.
I go into the server directory and make the changes as suggested to scheme.prisma:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native", "linux-musl"]
}
And yet when I try docker-compose up again it fails on the same error.
I have deleted node_modules multiple times and tried npx prisma generate but it's almost as if docker-compose is using the same old images.
I've also tried docker-compose up --force-recreate without luck.
My docker-compose.yml:
version: '3.4'
services:
server:
env_file: .env
build: ./server
working_dir: /usr/loft/server
environment:
- DATABASE_URL=postgresql://my_dbase_info
ports:
- "5000:5000"
networks:
- loft-app
client:
depends_on:
- server
build: ./client
stdin_open: true
ports:
- "3000:3000"
working_dir: /usr/loft/client
networks:
- loft-app
nginx:
depends_on:
- server
- client
restart: always
build:
dockerfile: Dockerfile
context: ./nginx
ports:
- "8080:80"
networks:
- loft-app
networks:
loft-app:
driver: bridge
my server Dockerfile:
FROM node:17-alpine
WORKDIR /usr/loft/server
ARG DATABASE_URL=""
ENV DATABASE_URL $DATABASE_URL
# Bundle app source
COPY . .
# Install app dependencies
RUN npm i -g npm#8 && npm i
RUN npx prisma generate
EXPOSE 5000
CMD [ "npm","run","prod" ]
I found the answer located in this article
$ docker-compose build
$ docker-compose up --force-recreate

Jest watch interactive with docker-compose

I have this docker compose file:
version: "2.4"
services:
mysql:
image: mysql:8.0
environment:
- MYSQL_ROOT_PASSWORD=mypasswd
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
timeout: 20s
retries: 10
phpmyadmin:
image: phpmyadmin/phpmyadmin:latest
ports:
- 8080:80
environment:
- PMA_HOST=mysql
depends_on:
mysql:
condition: service_healthy
app:
stdin_open: true
tty: true
build:
context: .
dockerfile: Dockerfile.dev
volumes:
- ./src:/usr/app/src
depends_on:
mysql:
condition: service_healthy
The app service is just a node image running some tests with jest. The CMD of that image is jest --watchAll
I would like it to be interactive and respond to my key presses, but I cannot get it to work. This is the output I get when I spin up the containers with docker-compose up:
PASS src/test.test.ts
Can connect to the database
✓ Can connect to the database (1 ms)
app_1 |
Test Suites: 1 passed, 1 total
app_1 | Tests: 1 passed, 1 total
app_1 | Snapshots: 0 total
app_1 | Time: 0.314 s
app_1 | Ran all test suites.
app_1 |
app_1 | Watch Usage
app_1 | › Press f to run only failed tests.
app_1 | › Press o to only run tests related to changed files.
app_1 | › Press p to filter by a filename regex pattern.
app_1 | › Press t to filter by a test name regex pattern.
app_1 | › Press q to quit watch mode.
app_1 | › Press Enter to trigger a test run.
aaaaaaaaaaaaaaaffffffffooooooo
ppppp
p
As you can see, it's ignoring my key presses, and just appends the letters to the output.
You can run your test suite from the host, connecting to a database running in Docker.
You need to add ports: to your database container to make it accessible from outside Docker:
services:
mysql:
ports:
# The first number can be any unused port on your host.
# The second number MUST be the standard MySQL port 3306.
- '3306:3306'
You don't show how you configure your application to connect to the database, but you will need to set something like MYSQL_HOST=127.0.0.1 (required; the standard MySQL libraries misinterpret localhost to mean "a Unix socket") and MYSQL_PORT=3306 (with the first number from ports:, optional that is the default port 3306 and required otherwise).
Once you've done this, you can run your tests:
# Start the database, but not the application
docker-compose up -d mysql
# Run the tests from the host, outside of Docker
npx jest --watchAll
This last command is a totally normal test-runner invocation. You do not need to do anything to cause source code to sync with the test runner or to pass keypresses through, because you are actually running your local source code with a local process.
what you expect is nonsense. this output is just for showing you the logs of your services and by docker-compose up: -d command this no longer showing for you.
for interact with you service you must dive into your container.
docker exec -it [CONTAINER_NAME] bash

How to deploy spring-cloud-config server in docker-compose?

I've got a problem with my docker-compose. I'm trying to create mulitple containers with one spring-cloud-config-server, and im trying to use spring-cloud server with my webapps container.
That's the list of my containers:
1 for the BDD (db)
1 for spring cloud config server (configproperties)
1 for some webapps (webapps)
1 nginx for reverse proxying (cnginx)
I already try to use localhost, my config-server name as host in environment variable : SPRING_CLOUD_CONFIG_URI and in boostrap.properties.
My 'configproperties' container, use 8085 in the server.xml.
That's my docker-compose.yml
version: '3'
services:
cnginx:
image: cnginx
ports:
- 80:80
restart: always
depends_on:
- configproperties
- cprocess
- webapps
db:
image: postgres:9.3
environment:
POSTGRES_USER: xxx
POSTGRES_PASSWORD: xxx
restart: always
command:
- -c
- max_prepared_transactions=100
configproperties:
restart: on-failure:2
image: configproperties
depends_on:
- db
expose:
- "8085"
environment:
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/mydbName?currentSchema=public
webapps:
restart: on-failure:2
image: webapps
links:
- "configproperties"
environment:
- SPRING_CLOUD_CONFIG_URI=http://configproperties:8085/config-server
- SPRING_PROFILES_ACTIVE=docker
depends_on:
- configproperties
expose:
- "8085"
When i run my docker-compose, my webapps are deploying with somme error like:
- Could not resolve placeholder 'repository.temps' in value "${repository.temps}"
But when i'm using postman and send a request like that :
http://localhost/config-server/myApplication/docker/latest
It's working properly, the request return all configuration for 'myApplication'.
I think i have miss somethink, but i don't find it...
Anyone can help me ?
Regards,
For using springcloud server, we just need to run our webapps after the initialisation of the springcloud server.
#!/bin/bash
CONFIG_SERVER_URL=$SPRING_CLOUD_CONFIG_URI/myApp/production/latest
#Check si le le serveur de config est bien lancé
echo 'Waiting for tomcat to be available'
attempt_counter=0
max_attempts=10
while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' $CONFIG_SERVER_URL)" != "200" ]]; do
if [ ${attempt_counter} -eq ${max_attempts} ];then
echo "Max attempts reached on $CONFIG_SERVER_URL"
exit 1
fi
attempt_counter=$(($attempt_counter+1))
echo "code retour $(curl -s -o /dev/null -w ''%{http_code}'' $CONFIG_SERVER_URL)"
echo "Attempt to connect to $CONFIG_SERVER_URL : $attempt_counter/$max_attempts"
sleep 15
done
echo 'Tomcat is available'
mv /usr/local/tomcat/webappsTmp/* /usr/local/tomcat/webapps/

Mongo DB: Message exceeds allowed max message size

¡Hi! I've just developed RoR application to work with MongoDB and works fine. I tried few http requests to the app with postman, also worked fine!
When I deployed the app using Docker, I got a MongoDB error that follows after any request:
MONGODB | Message exceeds allowed max message size. The max is 50331648.
ms_notifications_1 | 2017-09-29 21:16:48 +0000: HTTP parse error, malformed request (): # Puma::HttpParserError: Invalid HTTP format, parsing fails.
I'll be very thankful If anybody have the solution for this error. Thanks!
My compose file:
version: '2'
services:
ms_notifications_db:
image: mongo:latest
container_name: "rancher-node1" `
environment:
- MONGO_DATA_DIR=/data/db
- MONGO_LOG_DIR=/dev/null
volumes:
- ./data/db:/data/db
ports:
- "27017:27017"
command: mongod --smallfiles `
ms_notifications:
build: .
command: bash -c " rm -f tmp/pids/server.pid && bundle
exec rails db:migrate && bundle exec rails s -p 3007 -b '0.0.0.0'"
ports:
- "3007:3007"
depends_on:
- ms_notifications_db

How to properly connect containers created with multiple docker-compose files with isolated networks

I am trying to set up an extensible docker production environment for a few projects on a virtual machine.
My setup is as follows:
Front end: (this works as expected: thanks to Tevin Jeffery for this)
# ~/proxy/docker-compose.yml
version: '2'
services:
nginx-proxy:
image: jwilder/nginx-proxy
container_name: nginx-proxy
ports:
- '80:80'
- '443:443'
volumes:
- '/etc/nginx/vhost.d'
- '/usr/share/nginx/html'
- '/etc/nginx/certs:/etc/nginx/certs:ro'
- '/var/run/docker.sock:/tmp/docker.sock:ro'
networks:
- nginx
letsencrypt-nginx-proxy:
container_name: letsencrypt-nginx-proxy
image: 'jrcs/letsencrypt-nginx-proxy-companion'
volumes:
- '/etc/nginx/certs:/etc/nginx/certs'
- '/var/run/docker.sock:/var/run/docker.sock:ro'
volumes_from:
- nginx-proxy
networks:
- nginx
networks:
nginx:
driver: bridge
Database: (planning to add postgres to support rails apps as well)
# ~/mysql/docker-compose.yml
version: '2'
services:
db:
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: wordpress
# ports:
# - 3036:3036
networks:
- db
networks:
db:
driver: bridge
And finaly a wordpress blog to test if everything works:
# ~/wp/docker-compose.yml
version: '2'
services:
wordpress:
image: wordpress
# external_links:
# - mysql_db_1:mysql
ports:
- 8080:80
networks:
- proxy_nginx
- mysql_db
environment:
# for nginx and dockergen
VIRTUAL_HOST: gizmotronic.ca
# wordpress setup
WORDPRESS_DB_HOST: mysql_db_1
# WORDPRESS_DB_HOST: mysql_db_1:3036
# WORDPRESS_DB_HOST: mysql
# WORDPRESS_DB_HOST: mysql:3036
WORDPRESS_DB_USER: root
WORDPRESS_DB_PASSWORD: wordpress
networks:
proxy_nginx:
external: true
mysql_db:
external: true
My problem is that the Wordpress container can not connect to the database. I get the following error when I try to start (docker-compose up) the Wordpress container:
wordpress_1 | Warning: mysqli::mysqli(): (HY000/2002): Connection refused in - on line 22
wordpress_1 |
wordpress_1 | MySQL Connection Error: (2002) Connection refused
wp_wordpress_1 exited with code 1
UPDATE:
I was finally able to get this working. my main problem was relying on the container defaults for the environment variables. This created an automatic data volume with without a database or user for word press. After I added explicit environment variables to the mysql and Wordpress containers, I removed the data volume and restarted both containers. This forced the mysql container to recreate the database and user.
To ~/mysql/docker-compose.yml:
environment:
MYSQL_ROOT_PASSWORD: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_DATABASE: wordpress
and to ~/wp/docker-compose.yml:
environment:
# for nginx and dockergen
VIRTUAL_HOST: gizmotronic.ca
# wordpress setup
WORDPRESS_DB_HOST: mysql_db_1
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
One problem with docker-compose is that although sometimes your application is linked to your database, the application will NOT wait for your database to be up and ready. Here is an official Docker read:
https://docs.docker.com/compose/startup-order/
I've faced a similar problem where my test application would fail because it couldn't connect to my server because it wasn't up and running yet.
I made a similar workaround to the article posted in the link above by running a shell script to ping the address of the DB until it is available to be used. This script should be the last CMD command in your application.
RESPONSE=$(curl --write-out "%{http_code}\n" --silent --output /dev/null "YOUR_MYSQL_DATABASE:3306")
# Until the mysql sends a 200 HTTP response, we're going to keep checking
until [ $RESPONSE -eq "200" ]; do
sleep 2
echo "MySQL is not ready yet.. retrying... RESPONSE: ${RESPONSE}"
RESPONSE=$(curl --write-out "%{http_code}\n" --silent --output /dev/null "YOUR_MYSQL_DATABASE:3306")
done
# Once we know the server's up, we can start run our application
enter code to start your application here
I'm not 100% sure if this is the problem you're having. Another way to debug your problem is to run docker-compose in detached mode with the -d flag and run docker ps to see if your database is even running. If it is running, run docker logs $YOUR_DB_CONTAINER_ID to see if MySQL is giving you any errors when starting

Resources