Deploying a multi-container app on Azure App Services - python-3.x

I have been struggling for some days now to deploy an Azure App Service with two minimalist Docker containers.
My first image is a basic PostgreSQL image and my second image is built with the following Dockerfile:
FROM python:3.7
RUN pip install streamlit
COPY app.py /streamlit-docker/
WORKDIR /streamlit-docker/
CMD streamlit run app.py
and where app.py is:
import streamlit as st
st.write('Hello world')
The docker-compose.yml file I use for creating my Azure App service is the following:
version: '3.3'
services:
db:
image: atestcr.azurecr.io/postgres:latest
environment:
POSTGRES_PASSWORD: postgres
app:
image: atestcr.azurecr.io/my_app:latest
ports:
- '8501:8501'
I get an 'Application Error' whenever I try to access the webapp URL. However, when I deploy this app with a single docker container, using this docker-compose.yml:
version: '3.3'
services:
app:
image: atestcr.azurecr.io/my_app:latest
ports:
- '8501:8501'
everything works fine.
Here is a GitHub repo to recreate the bug.
These are the Azure logs:
2021-08-09T17:29:34.382Z INFO - Starting multi-container app..
2021-08-09T17:29:35.089Z INFO - Pulling image: atestcr.azurecr.io/postgres:latest
2021-08-09T17:29:35.313Z INFO - latest Pulling from postgres
2021-08-09T17:29:35.315Z INFO - Digest: sha256:b6df1345afa5990ea32866e5c331eefbf2e30a05f2a715c3a9691a6cb18fa253
2021-08-09T17:29:35.317Z INFO - Status: Image is up to date for atestcr.azurecr.io/postgres:latest
2021-08-09T17:29:35.319Z INFO - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-08-09T17:29:35.335Z INFO - Starting container for site
2021-08-09T17:29:35.335Z INFO - docker run -d -p 8477:5432 --name testapp32_db_0_6662435d -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=testapp32 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=testapp32.azurewebsites.net -e WEBSITE_INSTANCE_ID=42c09ff46e6c54cb467d28e88f2ab5b1e8971ee4daf2e883f44401bde67fe89f -e HTTP_LOGGING_ENABLED=1 atestcr.azurecr.io/postgres:latest
2021-08-09T17:29:35.781Z INFO - Pulling image: atestcr.azurecr.io/my_app:latest
2021-08-09T17:29:35.984Z INFO - latest Pulling from my_app
2021-08-09T17:29:35.987Z INFO - Digest: sha256:659937a52a6223b938b3d429901ab8648497870bf8068b5dcc05816050db5eaf
2021-08-09T17:29:35.988Z INFO - Status: Image is up to date for atestcr.azurecr.io/my_app:latest
2021-08-09T17:29:35.993Z INFO - Pull Image successful, Time taken: 0 Minutes and 0 Seconds
2021-08-09T17:29:36.014Z INFO - Starting container for site
2021-08-09T17:29:36.014Z INFO - docker run -d -p 0:8501 --name testapp32_app_0_6662435d -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=testapp32 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=testapp32.azurewebsites.net -e WEBSITE_INSTANCE_ID=42c09ff46e6c54cb467d28e88f2ab5b1e8971ee4daf2e883f44401bde67fe89f -e HTTP_LOGGING_ENABLED=1 atestcr.azurecr.io/my_app:latest
2021-08-09T17:33:26.741Z ERROR - multi-container unit was not started successfully
2021-08-09T17:33:26.846Z INFO - Container logs from testapp32_db_0_6662435d = 2021-08-09T17:29:40.459721366Z The files belonging to this database system will be owned by user "postgres".
2021-08-09T17:29:40.491740899Z This user must also own the server process.
2021-08-09T17:29:40.493019808Z
2021-08-09T17:29:40.497263739Z The database cluster will be initialized with locale "en_US.utf8".
2021-08-09T17:29:40.502456876Z The default database encoding has accordingly been set to "UTF8".
2021-08-09T17:29:40.503203182Z The default text search configuration will be set to "english".
2021-08-09T17:29:40.503218482Z
2021-08-09T17:29:40.503223282Z Data page checksums are disabled.
2021-08-09T17:29:40.506809008Z
2021-08-09T17:29:40.521275113Z fixing permissions on existing directory /var/lib/postgresql/data ... ok
2021-08-09T17:29:40.523912632Z creating subdirectories ... ok
2021-08-09T17:29:40.525237242Z selecting dynamic shared memory implementation ... posix
2021-08-09T17:29:40.642905697Z selecting default max_connections ... 100
2021-08-09T17:29:40.733900958Z selecting default shared_buffers ... 128MB
2021-08-09T17:29:41.039050775Z selecting default time zone ... Etc/UTC
2021-08-09T17:29:41.047757638Z creating configuration files ... ok
2021-08-09T17:29:44.416903507Z running bootstrap script ... ok
2021-08-09T17:29:50.023628737Z performing post-bootstrap initialization ... ok
2021-08-09T17:30:04.217544961Z syncing data to disk ... ok
2021-08-09T17:30:04.218321267Z
2021-08-09T17:30:04.219189873Z initdb: warning: enabling "trust" authentication for local connections
2021-08-09T17:30:04.219206473Z You can change this by editing pg_hba.conf or using the option -A, or
2021-08-09T17:30:04.219223973Z --auth-local and --auth-host, the next time you run initdb.
2021-08-09T17:30:04.219491175Z
2021-08-09T17:30:04.219513275Z Success. You can now start the database server using:
2021-08-09T17:30:04.219519575Z
2021-08-09T17:30:04.219523675Z pg_ctl -D /var/lib/postgresql/data -l logfile start
2021-08-09T17:30:04.219527775Z
2021-08-09T17:30:08.340584036Z waiting for server to start.......2021-08-09 17:30:08.340 UTC [44] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-08-09T17:30:08.478247580Z 2021-08-09 17:30:08.410 UTC [44] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-08-09T17:30:08.680599067Z 2021-08-09 17:30:08.680 UTC [45] LOG: database system was shut down at 2021-08-09 17:29:49 UTC
2021-08-09T17:30:08.753589768Z 2021-08-09 17:30:08.753 UTC [44] LOG: database system is ready to accept connections
2021-08-09T17:30:08.755965684Z done
2021-08-09T17:30:08.760382514Z server started
2021-08-09T17:30:09.790821978Z
2021-08-09T17:30:09.799723839Z /usr/local/bin/docker-entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
2021-08-09T17:30:09.802079455Z
2021-08-09T17:30:09.840304817Z 2021-08-09 17:30:09.834 UTC [44] LOG: received fast shutdown request
2021-08-09T17:30:09.862102366Z waiting for server to shut down....2021-08-09 17:30:09.861 UTC [44] LOG: aborting any active transactions
2021-08-09T17:30:09.950488072Z 2021-08-09 17:30:09.950 UTC [44] LOG: background worker "logical replication launcher" (PID 51) exited with exit code 1
2021-08-09T17:30:09.954360498Z 2021-08-09 17:30:09.950 UTC [46] LOG: shutting down
2021-08-09T17:30:13.063848848Z ...2021-08-09 17:30:13.063 UTC [44] LOG: database system is shut down
2021-08-09T17:30:13.138558463Z done
2021-08-09T17:30:13.140082774Z server stopped
2021-08-09T17:30:13.144102302Z
2021-08-09T17:30:13.162430928Z PostgreSQL init process complete; ready for start up.
2021-08-09T17:30:13.165654351Z
2021-08-09T17:30:14.083504086Z 2021-08-09 17:30:13.992 UTC [1] LOG: starting PostgreSQL 13.3 (Debian 13.3-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
2021-08-09T17:30:14.084760295Z 2021-08-09 17:30:14.011 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2021-08-09T17:30:14.084774095Z 2021-08-09 17:30:14.015 UTC [1] LOG: listening on IPv6 address "::", port 5432
2021-08-09T17:30:14.084779495Z 2021-08-09 17:30:14.082 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-08-09T17:30:14.156076187Z 2021-08-09 17:30:14.132 UTC [63] LOG: database system was shut down at 2021-08-09 17:30:12 UTC
2021-08-09T17:30:14.198749982Z 2021-08-09 17:30:14.176 UTC [1] LOG: database system is ready to accept connections
2021-08-09T17:30:15.006882460Z 2021-08-09 17:30:14.998 UTC [70] LOG: invalid length of startup packet
2021-08-09T17:30:16.112919592Z 2021-08-09 17:30:16.112 UTC [71] LOG: invalid length of startup packet
2021-08-09T17:30:17.178350344Z 2021-08-09 17:30:17.174 UTC [72] LOG: invalid length of startup packet
...
2021-08-09T17:33:25.735293291Z 2021-08-09 17:33:25.735 UTC [260] LOG: invalid length of startup packet
2021-08-09T17:33:29.142Z INFO - Container logs from testapp32_app_0_6662435d = 2021-08-09T17:30:24.010212694Z
2021-08-09T17:30:24.011085300Z You can now view your Streamlit app in your browser.
2021-08-09T17:30:24.011101800Z
2021-08-09T17:30:24.012092107Z Network URL: http://172.16.232.3:8501
2021-08-09T17:30:24.012855612Z External URL: http://20.40.148.207:8501
2021-08-09T17:30:24.013407416Z
2021-08-09T17:33:36.002Z INFO - Stopping site testapp32 because it failed during startup.

It's worth noting your shared example doesn't work because your docker-compose.yml is using your own private container registries.
However, tinkering around the edges I have managed to get your dummy example working with changes to the following files:
Your app dockerfile:
FROM python:3.7
RUN pip install streamlit
COPY app.py /streamlit-docker/
WORKDIR /streamlit-docker/
EXPOSE 80
CMD streamlit run app.py --server.port 80
And adjusting your docker-compose.yml
version: '3.3'
services:
db:
image: postgis/postgis:13-master
environment:
- POSTGRES_DB=counterfactualcovid
- POSTGRES_USER=django
- POSTGRES_PASSWORD=django
app:
image: testazurecontainerregistryajc.azurecr.io/mcmegaapp:latest
ports:
- '80:80'
Ignore the fact i've used a generic postgres docker image and my own private container registry for the images and you'll see the key changes are:
in the Dockerfile exposing port 80, and adding --server.port 80 to the streamlit CMD call
in the docker-compose.yml setting the port forwarding to 80:80
I /think/ your issues arise from the preview limitations for the multi-container web apps feature, so setting everything to work via port 80 appears to resolve this.

Related

Sqlalchemy does not see Postgresql db

I develop a web-app using Flask under Python3. I have a problem with connecting to postgresql via sqlalchemy.
Dockerfile:
FROM ubuntu:20.04
ENV LANG en_US.UTF-8
RUN apt update
RUN apt install -y python3-pip python3.8-dev
RUN apt install default-libmysqlclient-dev -y
RUN apt install libpq-dev -y
WORKDIR /app
ADD ./requirements.txt /app/requirements.txt
RUN pip3 install psycopg2
RUN --mount=type=cache,target=/root/.cache/pip pip3 install -r requirements.txt
RUN pip3 install -r requirements.txt
COPY . /app
ENV PYTHONPATH "${PYTHONPATH}:/app/src"
CMD ["gunicorn", "-c", "python:config.gunicorn", "--worker-class", "aiohttp.worker.GunicornWebWorker", "--pythonpath", "/app/src/", "src.main:app"]
docker-compose.yml:
services:
backend:
environment:
TZ: 'UTC'
volumes:
- ./src:/app/src
build:
context: .
restart: always
ports:
- '80:5000'
depends_on:
- postgres
links:
- postgres:postgres
postgres:
restart: always
image: postgres:latest
volumes:
- /var/lib/postgresql
environment:
POSTGRES_PASSWORD: 1234
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_INITDB_ARGS: "-A md5"
ports:
- "5432:5432"
Postgresql logs:
2022-08-03 14:21:46.773 UTC [1] LOG: starting PostgreSQL 14.4 (Debian 14.4-1.pgdg110+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit
2022-08-03 14:21:46.776 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
2022-08-03 14:21:46.776 UTC [1] LOG: listening on IPv6 address "::", port 5432
2022-08-03 14:21:46.781 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2022-08-03 14:21:46.787 UTC [27] LOG: database system was shut down at 2022-08-03 14:20:52 UTC
2022-08-03 14:21:46.794 UTC [1] LOG: database system is ready to accept connections
2022-08-03 14:21:50.342 UTC [1] LOG: received fast shutdown request
2022-08-03 14:21:50.344 UTC [1] LOG: aborting any active transactions
2022-08-03 14:21:50.347 UTC [1] LOG: background worker "logical replication launcher" (PID 33) exited with exit code 1
2022-08-03 14:21:50.347 UTC [28] LOG: shutting down
2022-08-03 14:21:50.365 UTC [1] LOG: database system is shut down
Python app logs:
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) could not connect to server: Connection refused
Is the server running on host "0.0.0.0" and accepting
TCP/IP connections on port 5432?
As you can see postgresql is running on 0.0.0.0:5432 and sqlalchemy tries to connect to 0.0.0.0:5432. Therefore, it is not very clear what it does not like.
If I remember correctly, when connecting to another service within a docker compose network, you have to connect using the service name as the host name - so postgres:5432 in your case.

Cannot start minikube in Windows 10 with Docker as driver

I tried to run Minikube v1.19.0 on my laptop first time, using Docker as driver, but no luck though. Here are the execution logs:
PS C:\Users\______\kubernetes> minikube start --driver=docker --alsologtostderr
I0916 19:01:44.059272 20464 out.go:278] Setting OutFile to fd 96 ...
I0916 19:01:44.059272 20464 out.go:291] Setting ErrFile to fd 100...
W0916 19:01:44.091562 20464 root.go:292] Error reading config file at C:\Users\proskos\.minikube\config\config.json: open C:\Users\proskos\.minikube\config\config.json: The system cannot find the file specified.
I0916 19:01:44.097634 20464 out.go:285] Setting JSON to false
I0916 19:01:44.110479 20464 start.go:108] hostinfo: {"hostname":"--------","uptime":118298,"bootTime":1631689806,"procs":291,"os":"windows","platform":"Microsoft Windows 10 Enterprise","platformFamily":"Standalone Workstation","platformVersion":"10.0.18363 Build 18363","kernelVersion":"10.0.18363 Build 18363","kernelArch":"x86_64","virtualizationSystem":"","virtualizationRole":"","hostId":"---------------"}
W0916 19:01:44.110479 20464 start.go:116] gopshost.Virtualization returned error: not implemented yet
I0916 19:01:44.113153 20464 out.go:157] 😄 minikube v1.19.0 on Microsoft Windows 10 Enterprise 10.0.18363 Build 18363
😄 minikube v1.19.0 on Microsoft Windows 10 Enterprise 10.0.18363 Build 18363
I0916 19:01:44.116296 20464 driver.go:322] Setting default libvirt URI to qemu:///system
W0916 19:01:50.237519 20464 docker.go:108] docker version returned error: deadline exceeded running "docker version --format {{.Server.Os}}-{{.Server.Version}}": exit status 1
I0916 19:01:50.244288 20464 out.go:157] ✨ Using the docker driver based on user configuration
✨ Using the docker driver based on user configuration
I0916 19:01:50.244288 20464 start.go:276] selected driver: docker
I0916 19:01:50.244810 20464 start.go:718] validating driver "docker" against <nil>
I0916 19:01:50.244810 20464 start.go:729] status for docker: {Installed:true Healthy:false Running:false NeedsImprovement:false Error:exit status 1
deadline exceeded running "docker version --format {{.Server.Os}}-{{.Server.Version}}"
k8s.io/minikube/pkg/minikube/registry/drvs/docker.status
/app/pkg/minikube/registry/drvs/docker/docker.go:104
k8s.io/minikube/pkg/minikube/registry.Status
/app/pkg/minikube/registry/global.go:140
k8s.io/minikube/pkg/minikube/driver.Status
/app/pkg/minikube/driver/driver.go:305
k8s.io/minikube/cmd/minikube/cmd.selectDriver
github.com/spf13/cobra.(*Command).execute
/go/pkg/mod/github.com/spf13/cobra#v1.1.3/command.go:856
github.com/spf13/cobra.(*Command).ExecuteC
/go/pkg/mod/github.com/spf13/cobra#v1.1.3/command.go:960
github.com/spf13/cobra.(*Command).Execute
/go/pkg/mod/github.com/spf13/cobra#v1.1.3/command.go:897
k8s.io/minikube/cmd/minikube/cmd.Execute
/app/cmd/minikube/cmd/root.go:156
main.main
/app/cmd/minikube/main.go:82
runtime.main
/usr/local/go/src/runtime/proc.go:225
runtime.goexit
/usr/local/go/src/runtime/asm_amd64.s:1371 Reason:PROVIDER_DOCKER_DEADLINE_EXCEEDED Fix:Restart the Docker service Doc:https://minikube.sigs.k8s.io/docs/drivers/docker/}
I0916 19:01:50.250032 20464 out.go:157]
W0916 19:01:50.250390 20464 out.go:222] 💣 Exiting due to PROVIDER_DOCKER_NOT_RUNNING: deadline exceeded running "docker version --format -": exit status 1
💣 Exiting due to PROVIDER_DOCKER_NOT_RUNNING: deadline exceeded running "docker version --format -": exit status 1
W0916 19:01:50.250390 20464 out.go:222] 💡 Suggestion: Restart the Docker service
💡 Suggestion: Restart the Docker service
W0916 19:01:50.250924 20464 out.go:222] 📘 Documentation: https://minikube.sigs.k8s.io/docs/drivers/docker/
📘 Documentation: https://minikube.sigs.k8s.io/docs/drivers/docker/
I0916 19:01:50.252904 20464 out.go:157]
Docker Desktop Service is up and running, though. The problem wasn't resolved by restarting Docker. Here are the details of my Docker desktop installation:
PS C:\Users\______\kubernetes> docker version
API version: 1.41
Go version: go1.16.6
Git commit: 3967b7d
Built: Fri Jul 30 19:58:50 2021
OS/Arch: windows/amd64
Context: default
Experimental: true
Server: Docker Engine - Community
Engine:
Version: 20.10.8
API version: 1.41 (minimum version 1.12)
Go version: go1.16.6
Git commit: 75249d8
Built: Fri Jul 30 19:52:10 2021
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.4.9
GitCommit: e25210fe30a0a703442421b0f60afac609f950a3
runc:
Version: 1.0.1
GitCommit: v1.0.1-0-g4144b63
docker-init:
Version: 0.19.0
GitCommit: de40ad0
Finally, my Docker Desktop installation is configured to run Linux containers:
docker info --format '{{.OSType}}'
linux
Could you help me find out why Minikube can't communicate with Docker?
Try these three commands sequentially:
minikube config set driver docker
minikube delete
minikube start --driver=docker
I might be wrong but in my personal opinion this is a docker version issue.
It is not a typical behavior to have such error in the situation when docker service is up&running.
status for docker: {Installed:true Healthy:false Running:false NeedsImprovement:false Error:exit status 1
deadline exceeded running "docker version --format {{.Server.Os}}-{{.Server.Version}}"
and
Exiting due to PROVIDER_DOCKER_NOT_RUNNING: deadline exceeded running "docker version --format -": exit status 1
💣 Exiting due to PROVIDER_DOCKER_NOT_RUNNING: deadline exceeded running "docker version --format -": exit status 1
My recommendations:
docker system prune to completeley delete docker cache, images, etc
remove completely minikube
now 2 options. Either try to again start minikube --driver-docker or uninstall docker and install 1-2 versions below. I would go in your case with last one.

Docker container startup hangs while trying to run voting app

I did the following:
https://github.com/dockersamples/example-voting-app
cd example-voting-app
Inside that there are number of files/folders
MAINTAINERS
LICENSE
Jenkinsfile
ExampleVotingApp.sln
README.md
docker-stack-windows-1809.yml
docker-stack-simple.yml
docker-compose.yml
docker-compose-windows.yml
docker-compose-windows-1809.yml
docker-compose-simple.yml
docker-compose-k8s.yml
docker-compose-javaworker.yml
architecture.png
kube-deployment.yml
k8s-specifications
docker-stack.yml
docker-stack-windows.yml
result
vote
worker
I did cd vote and executed following commands
docker build . -t voting-app
docker run -p 5000:80 voting-app
After I run docker run command, I see the following output, and nothing is happening . I am clueless, as there is no error messages etc.
[root#osboxes vote]# docker run -p 5000:80 voting-app
[2020-06-16 17:59:27 +0000] [1] [INFO] Starting gunicorn 19.10.0
[2020-06-16 17:59:27 +0000] [1] [INFO] Listening at: http://0.0.0.0:80 (1)
[2020-06-16 17:59:27 +0000] [1] [INFO] Using worker: sync
[2020-06-16 17:59:27 +0000] [9] [INFO] Booting worker with pid: 9
[2020-06-16 17:59:27 +0000] [10] [INFO] Booting worker with pid: 10
[2020-06-16 17:59:27 +0000] [11] [INFO] Booting worker with pid: 11
[2020-06-16 17:59:27 +0000] [12] [INFO] Booting worker with pid: 12
Please guide how to fix this issue, and how to get the vote app running on container.
My OS details are as follows:
NAME="CentOS Linux"
VERSION="7 (Core)"
Thanks
In my earlier answer, i got the app working, by building and running each image individually.
Finally, after spending few hours, I am finally able to create docker-compose.yml file and able to run the entire application using the following command:
docker-compose up
Hope it helps other who are struggling to make this application work.
docker-compose.yml
version: "3"
services:
redis:
image: redis
db:
image: postgres:9.4
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_HOST_AUTH_METHOD=trust
vote:
image: voting-app
ports:
- 5000:80
links:
- redis
worker:
image: worker-app
links:
- db
- redis
result:
image: result-app
ports:
- 5001:80
links:
- db
After code checkout, I followed the following steps, and got the voting application to run.
change to vote directory
docker run -d --name=redis redis
docker build . -t voting-app
docker run -p 5000:80 --link redis:redis voting-app
docker run -d --name=db -e POSTGRES_PASSWORD=postgres postgres:9.4
change to worker directory
docker build . -t worker-app
docker run --link redis:redis --link db:db worker-app
change to result directory
docker build . -t result-app
docker run -p 5001:80 --link db:db result-app
Access the URLs
http://<IP>:5000/
http://<IP>:5001/
Replace the IP with IP of your machine. Now I can access both the URLs.

Cannot connect to the Docker daemon at unix:///var/run/docker.sock in Azure hosted multi-container Web App

Using Azure Web Apps for Containers to spin up a docker-compose configuration. The primary proxy is Traefik which needs access to the docker API. The container start up correctly. But the traefik container can not access the docker API socket file.
The docker-compose settings for the volume of the traefik container is:
services:
traefik:
image: "traefik:v2.0"
[...]
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
[...]
The containers start up successfully with the following log:
2019-09-16 10:40:35.040 INFO - Pulling image from Docker hub:
library/traefik:v2.0 2019-09-16 10:40:35.589 INFO - v2.0 Pulling from
library/traefik 2019-09-16 10:40:35.810 INFO - Digest:
sha256:97c6da99b265de1c50e866ff66f927abb84659dcb7916c33e17623fc6969551c
2019-09-16 10:40:35.816 INFO - Status: Image is up to date for
traefik:v2.0 2019-09-16 10:40:35.835 INFO - Pull Image successful,
Time taken: 0 Minutes and 0 Seconds 2019-09-16 10:40:35.871 INFO -
Starting container for site 2019-09-16 10:40:35.872 INFO - docker run
-d -p 40317:80 --name containertest3_traefik_1_6d1c6629 -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e
WEBSITE_SITE_NAME=containertest3 -e WEBSITE_AUTH_ENABLED=False -e
WEBSITE_ROLE_INSTANCE_ID=0 -e
WEBSITE_HOSTNAME=containertest3.azurewebsites.net -e
WEBSITE_INSTANCE_ID=902eae0c51eb407ec9308de2a1c3fce2b35f53f6d148e328560acba2560930f0
-e HTTP_LOGGING_ENABLED=1 traefik:v2.0 --api.insecure=true --providers.docker=true --providers.docker.exposedbydefault=false --entrypoints.web.address=:80 --entryPoints.web.forwardedHeaders.insecure
2019-09-16 10:40:36.215 INFO - Pulling image from Docker hub:
containous/whoami 2019-09-16 10:40:36.779 INFO - latest Pulling from
containous/whoami 2019-09-16 10:40:36.780 INFO - Digest:
sha256:09229ae40edb92e95b15e90fef46bfadab14fd1ec2232aca717a501741fcf391
2019-09-16 10:40:36.788 INFO - Status: Image is up to date for
containous/whoami:latest 2019-09-16 10:40:36.790 INFO - Pull Image
successful, Time taken: 0 Minutes and 0 Seconds 2019-09-16
10:40:36.815 INFO - Starting container for site 2019-09-16
10:40:36.816 INFO - docker run -d -p 0:80 --name
containertest3_whoami_1_6d1c6629 -e
WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e
WEBSITE_SITE_NAME=containertest3 -e WEBSITE_AUTH_ENABLED=False -e
WEBSITE_ROLE_INSTANCE_ID=0 -e
WEBSITE_HOSTNAME=containertest3.azurewebsites.net -e
WEBSITE_INSTANCE_ID=902eae0c51eb407ec9308de2a1c3fce2b35f53f6d148e328560acba2560930f0
-e HTTP_LOGGING_ENABLED=1 containous/whoami
2019-09-16 10:40:47.048 INFO - Started multi-container app 2019-09-16
10:40:47.099 INFO - Initiating warmup request to container
containertest3_traefik_1_6d1c6629 for site containertest3 2019-09-16
10:40:47.101 INFO - Container containertest3_traefik_1_6d1c6629 for
site containertest3 initialized successfully and is ready to serve
requests.
However, in the error logs, Traefik can not acces the docker api and therefore does not work correctly:
2019-09-16T10:40:47.505909459Z time="2019-09-16T10:40:47Z" level=error
msg="Provider connection error Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?, retrying
in 1.080381816s" providerName=docker
2019-09-16T10:40:48.585335458Z time="2019-09-16T10:40:48Z" level=error
msg="Failed to retrieve information of the docker client and server
host: Cannot connect to the Docker daemon at
unix:///var/run/docker.sock. Is the docker daemon running?"
Final error for the Traefik container:
"Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?"
Any idea how to fix this error in the Azure app environment? Is this not possible within the Azure hosting/preview for App containers?
The Azure Web App service does not allow for reading from docker.sock.
You need to use another configuration provider in traefik if you want to run multi-container in Azure App Service.

Create Docker image for NodeJS + PostgreSQL web application

I've been reading Docker's documentation, but I can't get around creating an image that will work.
I have a NodeJS application that uses PostgreSQL as database:
var connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/db';
var pg = require('pg');
var pgp = require('pg-promise')();
var db = pgp(connectionString);
db.func('some_storedProcedure').then(//...)
//...
I first created a Dockerfile according to Node's documentation for it:
FROM node:argon
# Create app directory
RUN mkdir -p /app
WORKDIR /app
# Install app dependencies
COPY package.json /app
RUN npm install
# Bundle app source
COPY . /app
EXPOSE 5000
CMD [ "npm", "start" ]
I then followed this post regarding connecting the database to it with docker-compose. the docker-compose.yml file looks like:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/app
links:
- db
environment:
DATABASE_URL: postgres://myuser:mypass#db:5432/db
db:
image: postgres
environment:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: mypass
This is (some) of what is returned when I run docker-compose up with these files, after creating the image.
npm info ok
---> 87dbbae35721
Removing intermediate container c73f826a0b3d
Step 6 : COPY . /app
---> ec56bfc11d3c
Removing intermediate container 745ddf82d742
Step 7 : EXPOSE 5000
---> Running in b2be5aecd9d6
---> a7d126a7ea5e
Removing intermediate container b2be5aecd9d6
Step 8 : CMD npm start
---> Running in 0379d512c688
---> 266517f47311
Removing intermediate container 0379d512c688
Successfully built 266517f47311
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Starting imagename_db_1
Creating imagename_web_1
Attaching to imagename_db_1, imagename_web_1
web_1 | npm info it worked if it ends with ok
web_1 | npm info using npm#2.15.1
web_1 | npm info using node#v4.4.3
web_1 | npm info prestart SharedServer#5.8.0
web_1 | npm info start SharedServer#5.8.0
web_1 |
web_1 | > SharedServer#5.8.0 start /app
web_1 | > node index.js
web_1 |
web_1 | Wed, 27 Apr 2016 00:41:19 GMT body-parser deprecated bodyParser: use individual json/urlencoded middlewares at index.js:13:9
web_1 | Wed, 27 Apr 2016 00:41:19 GMT body-parser deprecated undefined extended: provide extended option at node_modules/body-parser/index.js:105:29
web_1 | Node app is running on port 5000
db_1 | LOG: database system was interrupted; last known up at 2016-04-25 00:17:59 UTC
db_1 | LOG: database system was not properly shut down; automatic recovery in progress
db_1 | LOG: invalid record length at 0/17076E8
db_1 | LOG: redo is not required
db_1 | LOG: MultiXact member wraparound protections are now enabled
db_1 | LOG: database system is ready to accept connections
db_1 | LOG: autovacuum launcher started
When I access http://localhost:5000, I see the web application running, but whenever I fire up something that tries to access the database, I get a HTTP 500 error with the following body
code: "28P01"
file: "auth.c"
length: 98
line: "285"
name: "error"
routine: "auth_failed"
severity: "FATAL"
What am I doing wrong? I'm not sure I understand what I'm doing with Docker, and the only thing I have for documentation are simple recipes to build specific environments (or at least, that's what I've understood)
Thanks.
Check your pg_hba.conf in $PGDATA allows connections from node.js.
By default the pg_hba.conf is like so:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
This is fine for your standard psql connectivity via the OS owner as it allows local connections trusted for localhost IP address 127.0.0.1. However if you have an IP address set on the server, which I'm guessing you do then you need to allow an entry for that because in your node.js configuration you're referring to a host of "DB". So ping "DB" and add that IP address:
# TYPE DATABASE USER ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
host db myuser <ip-for-db-host> md5
Once you've changed that file you will need to perform a pg_ctl reload.

Resources