可以在Docker-Compose中使用Bigning。

发布于 2025-02-12 10:05:09 字数 1407 浏览 3 评论 0原文

我正在通过Docker-Compose运行Rails 7应用程序。当我尝试在代码中使用binking.break时,我的附件终端显示了以下内容:

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)

但没有为我提供输入缓冲区以输入命令。我必须杀死该过程才能在服务器上执行任何操作。我的Docker-Compose包括

    tty: true
    stdin_open: true

,但仍然不起作用。有什么想法可以尝试什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行至春深 2025-02-19 10:05:09

例如:我有一个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 .

如果您进行调试,则必须使用docker contacter container_name访问应用程序的container_name。

例如:Docker附加Anywork_name。这对您有用。

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.

掐死时间 2025-02-19 10:05:09

I face the exact same problem. As described by Pedro Pava in comments, as a workaround, it works if I attached before sending the request but it hangs if I try to attach after.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文