相关文章推荐
玩篮球的灯泡  ·  EasyUi ...·  7 月前    · 
霸气的西装  ·  MethodInfo.MakeGeneric ...·  1 年前    · 
无邪的铁板烧  ·  package.json ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

docker-compose for portainer with traefik v2 gives "failure: unable to retrieve server settings and status"

Ask Question

I currently have a hard time updating my traefik v1 containers to v2. I set up a traefik container with automatic http->https forwarding. Now I want to get portainer running with the following docker-compose file:

version: '3.3'
volumes:
  portainer: {}
networks:
    external: true
services:
  portainer:
    image: portainer/portainer:latest
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data
    command: |
      --no-analytics
      --data /data
      --admin-password "the_hashed_password"
      -H unix:///var/run/docker.sock
    networks:
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.portainer.entrypoints=websecure"
      - "traefik.http.routers.portainer.rule=Host(`portainer.myserver.domain`)"
      - "traefik.http.services.portainer.loadbalancer.server.port=9000"
      - "traefik.http.routers.portainer.tls=true"
      - "traefik.http.routers.portainer.tls.certresolver=leresolver"
      - "traefik.http.routers.portainer.middlewares=authportainer"
      # generate with: sudo docker run --rm -ti xmartlabs/htpasswd user password
      - "traefik.http.middlewares.authportainer.basicauth.users=myuser:my_hashed_password"

Now when I start the container with docker-compose up I get:

portainer_1  | 2020/04/19 16:10:04 Starting Portainer 1.23.2 on :9000
portainer_1  | 2020/04/19 16:10:04 server: Listening on 0.0.0.0:8000...

Accessing http://portainer.myserver.domain correctly forwards to https://portainer.myserver.domain. After authenticating with myuser, an empty page is shown with a fading message toast "Failure. Unable to retrieve server settings and status". With traefik v1 the setup used to work. What I don't understand is if I need to do anything with port 8000 (which I didn't in the old working environment).

How does one debug such a scenario?
What is wrong with my docker-compose file?

P.S. For brevity, I omitted the traefik configuration file. If wanted, I will add it (it works with simple containers).

I encountered a similar problem and could solve it by extending the router rule (see also the Traefik documentation.):

- "traefik.http.routers.portainer.rule=Host(`portainer.myserver.domain`) || (Host(`portainer.myserver.domain`) && PathPrefix(`/api`))"

This way, Traefik should now route the api requests of the Portainer front-end correctly.

Hope this helps you too!

P.S. Regarding your debug question, I figured this one out by inspecting the network interaction by the browser, which revealed that all calls to portainer.myserver.domain/api/xyz returned a 404 error.

The networking tab in the browser is indeed a good point. I will try your suggestion later and upvote if it solves the problem. Thank you for the tips. – Pascal Jun 29, 2020 at 9:21 I was wondering shouldn't the first condition also include the 2nd? if the host is portainer.myserver.domain, then why do we need another condition with the same host AND some other condition? – Prasannjeet Singh Apr 18 at 20:40
  • The browser was/is at fault here
  • latest is not what it says (that one is unrelated but occurred to me during debugging)
  • Regarding the browser - I use Firefox 78.0.1 and always worked on docker from one specific machine. It seems that some data was cached that should not have been cached, with the cache leading to the faulty page. I don't know if portainer stored some data in the browsers cache (like cookies), but making it forget about the site (see here) made portainer work normally. Note that pressing F5 or Shift+F5 didn't work here, neither did restarting the browser.

    If you encounter a similar issue, you can also load the page in a private window. Depending on your configuration of your brower, this should prevent it to use previously cached data.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.