Giter VIP home page Giter VIP logo

Comments (3)

mavogel avatar mavogel commented on August 18, 2024 1

Container

I added a default port 32768 for a docker container if no external port is given. Due to terraform internals and tfstate sync I could not achieve an empty port or a computed port which is the same as the internal one.

provider "docker" {
  version = "1.0.2"
}

resource "docker_image" "centos-box" {
  name         = "centos:latest"
  keep_locally = true
}

resource "docker_container" "app-server" {
  name  = "app-server"
  image = "${docker_image.centos-box.latest}"

  ports = [
    {
      internal = 8443
      external = 8443
    },
    {
      internal = 22
      external = 22
    },
  ]
}

and the corresponding state

{
    "version": 3,
    "terraform_version": "0.11.8",
    "serial": 5,
    "lineage": "4de1b64c-bdfb-f66a-a5b9-4fdf361e45b6",
    "modules": [
        {
            "path": [
                "root"
            ],
            "outputs": {},
            "resources": {
                "docker_container.app-server": {
                    "type": "docker_container",
                    "depends_on": [
                        "docker_image.centos-box"
                    ],
                    "primary": {
                        "id": "033b6a8a57be32b788d33d9c5387bdd13f3e471a61aa52bdcbb69fc87b95c9d5",
                        "attributes": {
                            "bridge": "",
                            "gateway": "172.17.0.1",
                            "id": "033b6a8a57be32b788d33d9c5387bdd13f3e471a61aa52bdcbb69fc87b95c9d5",
                            "image": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6d",
                            "ip_address": "172.17.0.2",
                            "ip_prefix_length": "16",
                            "log_driver": "json-file",
                            "must_run": "true",
                            "name": "app-server",
                            "ports.#": "2",
                            "ports.1670854030.external": "8443",
                            "ports.1670854030.internal": "8443",
                            "ports.1670854030.ip": "",
                            "ports.1670854030.protocol": "tcp",
                            "ports.362530277.external": "22",
                            "ports.362530277.internal": "22",
                            "ports.362530277.ip": "",
                            "ports.362530277.protocol": "tcp",
                            "restart": "no"
                        },
                        "meta": {},
                        "tainted": false
                    },
                    "deposed": [],
                    "provider": "provider.docker"
                },
                "docker_image.centos-box": {
                    "type": "docker_image",
                    "depends_on": [],
                    "primary": {
                        "id": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6dcentos:latest",
                        "attributes": {
                            "id": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6dcentos:latest",
                            "keep_locally": "true",
                            "latest": "sha256:75835a67d1341bdc7f4cc4ed9fa1631a7d7b6998e9327272afea342d90c4ab6d",
                            "name": "centos:latest"
                        },
                        "meta": {},
                        "tainted": false
                    },
                    "deposed": [],
                    "provider": "provider.docker"
                }
            },
            "depends_on": []
        }
    ]
}

Service

Nevertheless @laimVM, AFAICS you wanted to achieve to ramp up multiple containers of an image with the terraform-docker version 0.1.1 which was pre #40. Now you should be able to achieve starting multiple replicas of a service via

resource "docker_service" "app-server" {
  name = "app-server"

  task_spec {
    container_spec = {
      image = "${docker_image.centos-box.latest}"
    }
  }

  mode {
    replicated {
      replicas = 2
    }
  }

  endpoint_spec {
    ports = [
      {
        target_port    = "8443"
        published_port = "8443"
      },
      {
        target_port    = "80"
        published_port = "80"
      },
    ]
  }
}

HTH Manu

from terraform-provider-docker.

iainvm avatar iainvm commented on August 18, 2024

So am I understanding this change correctly, before a random external port was assigned, but the tfstate didn't pick it up. Though now the external port is just assumed to be 32678. This means I can't use the randomly assigned ports provided by docker, and must specify the external port in all cases?

from terraform-provider-docker.

mavogel avatar mavogel commented on August 18, 2024

This means I can't use the randomly assigned ports provided by docker, and must specify the external port in all cases?

Yes, atm it is like this. But let me find a solution with the core team how to handle it correctly. My first thought with Computed: true from the docs and other approaches did not work. I'll track it in #102

from terraform-provider-docker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.