기본적으로 Container-Optimized OS 호스트 방화벽은 나가는 연결을 허용하고 SSH 서비스를 통해서 새로 추가되는 연결만 수락합니다. Container-Optimized OS를 실행하는 VM 인스턴스에서 sudo iptables -L을 실행하여 정확한 호스트 방화벽 구성을 볼 수 있습니다.
호스트 방화벽은 올바른 애플리케이션 작동을 위해 구성되어야 하는 Virtual Private Cloud 방화벽 규칙과 다르다는 것에 유의하세요.
Virtual Private Cloud 방화벽 규칙에 대한 자세한 내용은 방화벽 규칙 개요를 참조하세요.
Docker 기본 네트워크 네임스페이스에서 컨테이너 실행
네트워크에서 액세스할 수 있어야 하는 컨테이너를 Container-Optimized OS에 배포하지만 Docker --net=host 옵션을 사용하지 않을 때는 Docker -p 옵션으로 컨테이너를 실행합니다. 이 옵션을 사용하면 네트워크에서 애플리케이션을 노출하도록 Docker가 호스트 방화벽을 자동으로 구성합니다. Docker 실행 옵션에 대한 자세한 내용은 Docker 실행 참조를 확인하세요.
다음 예시에서 nginx 컨테이너는 네트워크 포트 80에서 액세스할 수 있습니다.
dockerrun--rm-d-p80:80--name=nginxnginx
호스트 네트워크 네임스페이스에서 컨테이너 실행
네트워크에서 액세스할 수 있어야 하는 컨테이너를 Container-Optimized OS에 배포하지만 Docker --net=host 옵션을 사용하지 않을 때는 호스트 방화벽을 직접 명시적으로 구성해야 합니다.
표준 iptables 명령어로 호스트 방화벽을 구성할 수 있습니다. 대부분의 GNU/Linux 배포판에서와 같이 iptables 명령어로 구성된 방화벽 규칙은 재부팅 시에 유지되지 않습니다. 부팅할 때마다 호스트 방화벽이 올바르게 구성되도록 하려면 cloud-init 구성에서 호스트 방화벽을 구성합니다. 다음 cloud-init 예시를 참조하세요.
#cloud-configwrite_files:-path:/etc/systemd/system/config-firewall.servicepermissions:0644owner:rootcontent:|[Unit]Description=Configures the host firewall[Service]Type=oneshotRemainAfterExit=trueExecStart=/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT-path:/etc/systemd/system/myhttp.servicepermissions:0644owner:rootcontent:|[Unit]Description=My HTTP serviceAfter=docker.service config-firewall.serviceWants=docker.service config-firewall.service[Service]Restart=alwaysExecStart=/usr/bin/docker run --rm --name=%n --net=host nginxExecStop=-/usr/bin/docker exec %n -s quitruncmd:-systemctl daemon-reload-systemctl start myhttp.service
Container-Optimized OS를 실행하는 VM에 이 cloud-init 구성을 사용하면 부팅할 때마다 다음 동작이 수행됩니다.
포트 80에서 새로 추가되는 TCP 연결을 허용하도록 호스트 방화벽이 구성됩니다.
nginx 컨테이너가 포트 80으로 리슨하고 새로 추가되는 HTTP 요청에 응답합니다.
Container-Optimized OS에서 cloud-init 사용에 대한 자세한 내용은 인스턴스 만들기 및 구성을 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2024-12-17(UTC)"],[[["\u003cp\u003eBy default, Container-Optimized OS allows outgoing connections and only accepts incoming connections via SSH, as seen with the \u003ccode\u003esudo iptables -L\u003c/code\u003e command, but this might vary with other Google Cloud products.\u003c/p\u003e\n"],["\u003cp\u003eUsing Docker's \u003ccode\u003e-p\u003c/code\u003e option automatically configures the host firewall for network accessibility when deploying a container on Container-Optimized OS without \u003ccode\u003e--net=host\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eFor IPv6 accessibility, the host firewall must be manually configured using \u003ccode\u003eip6tables\u003c/code\u003e commands because Docker does not automatically configure the IPv6 rules.\u003c/p\u003e\n"],["\u003cp\u003eWhen deploying a container on Container-Optimized OS with Docker's \u003ccode\u003e--net=host\u003c/code\u003e option, you must manually configure the host firewall with \u003ccode\u003eiptables\u003c/code\u003e commands.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure persistent host firewall configurations across reboots when using \u003ccode\u003eiptables\u003c/code\u003e commands, utilize \u003ccode\u003ecloud-init\u003c/code\u003e to set up the firewall rules, such as allowing incoming TCP connections on port 80.\u003c/p\u003e\n"]]],[],null,["# Configuring the host firewall\n\nBy default, the Container-Optimized OS host firewall allows outgoing\nconnections and accepts incoming connections only through the SSH service. You\ncan see the exact host firewall configuration by running `sudo iptables -L` on a\nVM instance running Container-Optimized OS.\n| **Warning:** The default firewall configuration might be different if you are using Container-Optimized OS through another Google Cloud product like [Containers on Compute Engine](/compute/docs/containers/deploying-containers) or Google Kubernetes Engine. Refer to the product specific documentation for more details.\n\nKeep in mind that the host firewall is different from Virtual Private Cloud firewall\nrules, which must also be configured for your applications to work correctly.\nSee the [Firewall Rules Overview](/vpc/docs/firewalls) to learn more about\nVirtual Private Cloud firewall rules.\n\nRunning containers in Docker's default network namespace\n--------------------------------------------------------\n\nIf you are deploying a container on Container-Optimized OS that must be\naccessible over the network and you are not using Docker's `--net=host` option,\nrun your container with Docker's `-p` option. With this option, Docker will\nautomatically configure the host firewall to expose your application on the\nnetwork. See the\n[Docker run reference](https://docs.docker.com/engine/reference/run/) to learn\nmore about Docker run options.\n\nIn the following example, the `nginx` container will be accessible on the\nnetwork on port 80: \n\n docker run --rm -d -p 80:80 --name=nginx nginx\n\n| **Note:** If IPv6 address is used for accessing the deployed container over the network, you must explicitly configure the host firewall using `ip6tables` commands like `\"ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT\"`.This is because Docker does not automatically configure the IPv6 rules for host firewall to expose your application on the network due to [known limitation](https://github.com/moby/moby/issues/21951).\n\nRunning containers in the host's network namespace\n--------------------------------------------------\n\nIf you are deploying a container on Container-Optimized OS that must be\naccessible over the network and you are using Docker's `--net=host` option, you\nmust explicitly configure the host firewall yourself.\n\nYou can configure the host firewall with standard `iptables` commands. As with\nmost GNU/Linux distributions, firewall rules configured with `iptables` commands\nwill not persist across reboots. To ensure that the host firewall is correctly\nconfigured on every boot, configure the host firewall in your `cloud-init`\nconfiguration. Consider the following `cloud-init` example: \n\n #cloud-config\n\n write_files:\n - path: /etc/systemd/system/config-firewall.service\n permissions: 0644\n owner: root\n content: |\n [Unit]\n Description=Configures the host firewall\n\n [Service]\n Type=oneshot\n RemainAfterExit=true\n ExecStart=/sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT\n - path: /etc/systemd/system/myhttp.service\n permissions: 0644\n owner: root\n content: |\n [Unit]\n Description=My HTTP service\n After=docker.service config-firewall.service\n Wants=docker.service config-firewall.service\n\n [Service]\n Restart=always\n ExecStart=/usr/bin/docker run --rm --name=%n --net=host nginx\n ExecStop=-/usr/bin/docker exec %n -s quit\n\n runcmd:\n - systemctl daemon-reload\n - systemctl start myhttp.service\n\nUsing this `cloud-init` configuration with a VM running\nContainer-Optimized OS will result in the following behaviors on every\nboot:\n\n- The host firewall will be configured to allow incoming TCP connections on port 80.\n- An `nginx` container will listen on port 80 and respond to incoming HTTP requests.\n\nRefer to\n[Creating and configuring instances](/container-optimized-os/docs/how-to/create-configure-instance)\nto learn more about using `cloud-init` on Container-Optimized OS."]]