Docker:如何使用docker-compose和no iptables阻止来自docker网络的传出流量? [英] Docker: How to prevent outgoing traffic from a docker's network using docker-compose and no iptables?

查看:122
本文介绍了Docker:如何使用docker-compose和no iptables阻止来自docker网络的传出流量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Alpine Linux用作容器的基础,因此对我来说没有iptables,我宁愿不必为此添加它.

I'm using Alpine Linux as a base for my containers, so no iptables for me, and I would rather not have to add it only for that.

我找到了这个答案: https://stackoverflow.com/a/42336592/1326863 告诉您答案是可以在docker的网络中禁用Internet,但是可以在docker-compose配置中做到吗?

I found this answer: https://stackoverflow.com/a/42336592/1326863 that tells that it is possible to disable internet in a docker's network, but is it possible to do it in docker-compose configuration?

推荐答案

在我的测试中,该数据库容器无法访问Internet:

This db container cannot reach the Internet in my tests:

version: '3'

services:
  db:
    image: postgres:alpine

networks:
  default:
    internal: true

这篇关于Docker:如何使用docker-compose和no iptables阻止来自docker网络的传出流量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆