# Expose a Docker container without labels

**URL:** <https://community.traefik.io/t/expose-a-docker-container-without-labels/1907>\
**Category:** Traefik v2\
**Tags:** file, docker\
**Created:** [September 26, 2019, 7:13am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907 "2019-09-26T07:13:47Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gm.cinalli](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/gm.cinalli/32/776_2.png) [@gm.cinalli](https://community.traefik.io/u/gm.cinalli)\
**Post date:** [September 26, 2019, 7:13am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/1 "2019-09-26T07:13:47Z")

</div>

Hi there,  
just a quick question, is it possible to expose a Docker container without the use of the labels inside the docker-compose file?

Here are my labels:

```yaml
      - traefik.enable=true
      - traefik.http.routers.container_name.rule=Host(`...`)
      - traefik.http.routers.container_name.entrypoints=https
      - traefik.http.routers.container_name.tls.certresolver=letsencrypt
      - traefik.http.routers.container_name.service=container_name
      - traefik.http.services.container_name.loadbalancer.server.port=8080

```

I want to change this configuration and use only the dynamic\_conf.yml (or TOML) file.

I've already tried that, but Traefik doesn't recognize the Docker container as a Docker service (_container\_name@docker_) but as a file service (_container\_name@file_).

Is there anything wrong with what I do or the only way to expose a Docker container is now through the use of labels?

Thank tou!

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [September 26, 2019, 11:56am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/2 "2019-09-26T11:56:11Z")

</div>

in `service_name@docker` and `service_name@file` what you have on the right side of `@` is not a service but configuration provider. If you provide configuration via docker labels then it's `@docker` if you provide it via dynamic\_conf.yml (or TOML) file, then it's `@file`

---

<div class="post-metadata">

**Author:** ![gm.cinalli](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/gm.cinalli/32/776_2.png) [@gm.cinalli](https://community.traefik.io/u/gm.cinalli)\
**Post date:** [September 26, 2019, 12:53pm UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/3 "2019-09-26T12:53:22Z")

</div>

Sorry, I was wrong to write, the concept of provider is clear to me, my question is then this: it is possible to expose a Docker container through the dynamic\_conf.yml file or the only way to do it is to insert the labels directly in the docker-compose .yml file?

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [September 26, 2019, 1:14pm UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/4 "2019-09-26T13:14:14Z")

</div>

Sure. What seems to be the problem?

---

<div class="post-metadata">

**Author:** ![gm.cinalli](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/gm.cinalli/32/776_2.png) [@gm.cinalli](https://community.traefik.io/u/gm.cinalli)\
**Post date:** [September 26, 2019, 3:22pm UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/5 "2019-09-26T15:22:13Z")

</div>

There is nothing wrong with that, but I had misunderstood then, I thought I could centralize everything in the _dynamic\_conf.yml_ file and leave the _docker-compose.yml_ without traefik stuff.

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [September 26, 2019, 9:32pm UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/6 "2019-09-26T21:32:11Z")

</div>

But you can. What I asked you above is what seems to be the problem with that?

My guess is that you tried, saw some error or unexpeted behaviour and mis-interpreted it. But unless you say what it is, it's very difficult to help.

Caveat: you can centralize _dymaic configuration_ there which is not to be mixed with _static configuration_ But in practical sense that should be what you are after anyway. You do not have to use docker-compose and you do not have to use labels.

---

<div class="post-metadata">

**Author:** ![raph](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@raph](https://community.traefik.io/u/raph)\
**Post date:** [October 2, 2019, 12:50am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/7 "2019-10-02T00:50:03Z")

</div>

Hello, I'm on the same question,

how can we use Docker provider without label ?

I would like something like :

```auto
[http.services.adminer]
  [http.services.adminer.loadbalancer.server]
    port = 8080

[http.routers.adminer]
  rule = "Host(`dev.localhost`) && PathPrefix(`/adminer`)"
  entrypoints = ["web"]
  service = "adminer"

```

how can i bind it to my docker service dynamically without to much labels ?  
someone would have an example maybe?

thank you

edit : is it a good practice?

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [October 2, 2019, 1:07am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/8 "2019-10-02T01:07:26Z")

</div>

Hello,

here is [dynamic configuration reference](https://docs.traefik.io/reference/dynamic-configuration/file/) for the file provider. You can use that instead of labels.

In your example you will need instead of specifying service port specify [service url](https://docs.traefik.io/routing/services/#weighted-round-robin-service).

The disadvantage is of course since you are not using docker provider (which is label based) you will not have the automatic discovery.

> [@raph](#):
>
> edit : is it a good practice?

What problem are you trying to solve? Everything fits to respective purpose. Docker labels with docker is probably the most convenient way working with docker, because of the discovery. However sometimes it's convenient to control traefik externally. While API achieves that, it is not persisted, so the File Provider is the best bet then. Obviously, it's most useful when your services/backends are outside of the docker instance that hosts traefik.

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [October 2, 2019, 2:11am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/9 "2019-10-02T02:11:48Z")

</div>

> [@raph](#):
>
> how can we use Docker provider without label ?

To use Docker without labels, you will to known the IP and the port of your container.

```auto
[http.services.adminer]
  [http.services.adminer.loadbalancer.server]
    url = http://<the-container-IP>:<port>

[http.routers.adminer]
  rule = "Host(`dev.localhost`) && PathPrefix(`/adminer`)"
  entrypoints = ["web"]
  service = "adminer"

```

There are 3 main problems with that:

1. the container IP is dynamic
2. the container need to expose port
3. Traefik cannot discover the new containers or the changes.

> [@raph](#):
>
> is it a good practice?

1. As the IP is dynamic, if a container restart the application provided by the container will be unavailable.
2. The fact to expose the ports of the containers is not a good practice and can produce some security issues.
3. If Traefik cannot detect new containers, you lost the most important things of Traefik: the automatic discovery and the automatic update.

**So I strongly advise against doing this, whether in terms of stability or security.**

The file provider has been made for the old infrastructures, based on VM or server manually managed, so I cannot recommend to use it for define routers and services for containers.

You can use it (the file provider) to define middlewares, some TLS things, and in this case it's a good idea.

---

<div class="post-metadata">

**Author:** ![zespri](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/zespri/32/310_2.png) [@zespri](https://community.traefik.io/u/zespri)\
**Post date:** [October 2, 2019, 4:58am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/10 "2019-10-02T04:58:36Z")

</div>

@ldez I don't have any reference to documentation hand to back this up, but if memory serves me well it does not have to be _ip address_. If you are on the same docker network (as traefik) you can address your container by name (and port). Also in this case you do not have to expose the port on the non-traefik container.

This largely mitigates poits 1 and 2 at the bottom of your post. 3 though still stands and is a very strong reason to prefer labels.

Example:

> **docker-compose.yaml**
>
> ```auto
> version: "3.3"
> services:
> traefik:
> image: "traefik:v2.0.0"
> container_name: "traefik"
> command:
> - --entryPoints.web.address=:80
> - --providers.file.filename=/dyn.toml
> ports:
> - "80:80"
> - "443:443"
> - "8080:8080"
> volumes:
> - "/var/run/docker.sock:/var/run/docker.sock:ro"
> - "./dyn.toml:/dyn.toml"
> whoami:
> image: "containous/whoami"
> container_name: "whoami"
> 
> ```

> **dyn.toml**
>
> ```auto
> [http.routers.main]
> entryPoints = ["web"]
> service = "main"
> rule = "PathPrefix(`/`)"
> 
> [http.services.main.loadBalancer]
> passHostHeader = true
> [[http.services.main.loadBalancer.servers]]
> url = "http://whoami"
> 
> ```

---

<div class="post-metadata">

**Author:** ![raph](https://avatars.discourse-cdn.com/v4/letter/r/e8c25b/32.png) [@raph](https://community.traefik.io/u/raph)\
**Post date:** [October 2, 2019, 5:19am UTC](https://community.traefik.io/t/expose-a-docker-container-without-labels/1907/11 "2019-10-02T05:19:47Z")

</div>

@zespri @ldez thanks for your help, I understand better now 🙂
