Fastapi: Deployment using docker-machine

Created on 19 Aug 2019  路  5Comments  路  Source: tiangolo/fastapi

I'm having trouble getting deployment to work for the out-of-the-box "full-stack-fastapi-postgresql" template using the instructions on the README file as well as what I've read on DockerSwarm.rocks. Here are the steps I've taken:

  1. I used docker-machine to create a VPS on azure with docker installed.
  2. I set the domain name of the machine to "fastapitest" such that the DNS of the machine is fastapitest.uksouth.cloudapp.azure.com
  3. I used cookiecutter to set up a project based on the "full-stack-fastapi-postgresql" template, I used the DNS name of the VPS set in (2) above for the "DOMAIN" variable during configuration and used docker-compose to check everything worked locally - wich it did
  4. I used docker-machine env so that I can run docker commands directly on the machine
  5. I used docker swarm init to initialise a single machine cluster
  6. I ran the "build" script as described in the README file:
    TAG=prod FRONTEND_ENV=production bash ./scripts/build.sh
  7. I rang the "deploy" script as described in the README file:
DOMAIN=fastapitest.uksouth.cloudapp.azure.com \
TRAEFIK_TAG=fastapitest.uksouth.cloudapp.azure.com \
STACK_NAME=fastapitest \
TAG=prod \
bash ./scripts/deploy.sh

I get the following output:

WARNING: Some services (backend, db, flower, frontend, pgadmin, proxy) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
--- 
+++ 
Label: fastapitestTAG=prod.app-db-data 
With value: true 
Assigned to node in hostname: fastapi-test 
With node ID: s885d1okylneu7043t9af6q2i 
--- 

network "traefik-public" is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed

Do I need to create a network with that name on my VPS? Azure automatically sets up a Network interface with a Virtual Network/Subnet called: docker-machine-vnet/docker-machine, is this releated?

question

All 5 comments

@DrNickMartin

I'm not sure exactly what the problem is, but for what it's worth this looks to me more likely to be a docker swarm configuration issue than a VPS issue.


If I had to guess, I think maybe you didn't create the traefik-public network?

See here -- search for the code block:

docker network create --driver=overlay traefik-public

@dmontagu
Thanks - that worked. The stack deploys on the VPS now and all the services appear to be up and running. The only issue is that if I navigate/curl to the domain (or directly to IP address) I get an ERR_CONNECTION_REFUSED. Port 80 is open to all incoming TCP traffic.

I guess I'm still not setting up Traefik correctly with the azure VPS, perhaps it doesn't like the Azure generated domain I'm using? The log from the proxy service (traefik) is just repeated outputting:

time="2019-08-18T22:56:19Z" level=info msg="Skipping same configuration for provider docker"

1) Make sure that you can curl the server from the same machine
2) Make sure there is nothing funny happening with route prefixes
3) See if you can access a server running on the same machine that should definitely work and not be broken due to traefik configuration (something like a jupyter notebook, or just run a uvicorn server outside of docker). That should help you determine whether it is a traefik error or a DNS/other error. If you aren't seeing anything in the traefik logs indicating connections are being rejected, the problem may exist somewhere entirely outside of docker.

Thanks for your help @dmontagu ! :rocket: :cake: :bowing_man:

Thanks @DrNickMartin for reporting back and closing the issue :tada:

@n1ckdm What did you do to fix the ERR_CONNECTION_REFUSED? I have the same error?

Nevermind. I think I finally got it.

I had to do a bunch of stuff. Probably more than necessary since I don't know what I am doing. I did the following and it seems to work with docker stack deploy

  1. upgrade to Traefik 2.0 and convert the labels to that format.
  2. specify ports for proxy in a file docker-compose.deploy.ports.yml
  3. specify a Traefik port for each service; e.g., "traefik.http.services.flower.loadbalancer.server.port=5555"
  4. add "--providers.docker.swarmMode=true" to docker-compose.deploy.command.yml
Was this page helpful?
0 / 5 - 0 ratings