I am trying to host a multi container app (web api+ postgres db) in azure using azure container registry as image source.
This is the docker compose file I am using:
version: '3.4'
services:
dockerapi:
image: test.azurecr.io/pgdemo:1
ports:
- "1985:80"
postgresimage:
image: postgres
ports:
- "5432"
environment:
POSTGRES_USER: "bloguser"
POSTGRES_PASSWORD: "bloguser"
POSTGRES_DB: "blogdb"
volumes:
- $./dbscripts/seed.sql :/docker-entrypoint-initdb.d/seed.sql
- db-data:/var/lib/postgresql/data
volumes:
db-data:
driver: local
I followed this article to develop this application and everything went well in local environment. It seems the volumes
section is not proper in docker-compose file. I tried replacing .
with WEBAPP_STORAGE_HOME
and still the seed scripts are ignored it seems from azure conatainer logs:
Microsoft.EntityFrameworkCore.Database.Command[20102] 2019-06-18T07:00:20.279183157Z Failed executing DbCommand (41ms) [Parameters=[], CommandType='Text', CommandTimeout='30'] 2019-06-18T07:00:20.279189958Z SELECT b.id, b.title, b.description 2019-06-18T07:00:20.279193958Z FROM blog AS b 2019-06-18T07:00:20.298436041Z WHERE STRPOS(b.title, 'Title') > 0 2019-06-18T07:00:20.298452842Z Npgsql.PostgresException (0x80004005): 42P01: relation "blog" does not exist 2019-06-18T07:00:20.298457842Z at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<g__ReadMessageLong|0>d.MoveNext() 2019-06-18T07:00:20.298462242Z --- End of stack trace from previous location where exception was thrown --- 2019-06-18T07:00:20.298466242Z at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<g__ReadMessageLong|0>d.MoveNext() 2019-06-18T07:00:20.298478543Z --- End of stack trace from previous location where exception was thrown --- 2019-06-18T07:00:20.298482943Z at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming) 2019-06-18T07:00:20.298486743Z at Npgsql.NpgsqlDataReader.NextResult() 2019-06-18T07:00:20.298490643Z
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) 2019-06-18T07:00:20.298494543Z at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) 2019-06-18T07:00:20.298498343Z at System.Data.Common.DbCommand.ExecuteReader() 2019-06-18T07:00:20.298502143Z at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
Is it the right way to add data volumes in azure?
To add data volume for the Web App for Container in Azure, you need to mount the path in the volume like this:
version: '3.4'
services:
dockerapi:
image: test.azurecr.io/pgdemo:1
ports:
- "1985:80"
postgresimage:
image: postgres
ports:
- "5432"
environment:
POSTGRES_USER: "bloguser"
POSTGRES_PASSWORD: "bloguser"
POSTGRES_DB: "blogdb"
volumes:
- ${WEBAPP_STORAGE_HOME}/dbscripts:/docker-entrypoint-initdb.d
- db-data:/var/lib/postgresql/data
volumes:
db-data:
driver: local
And then set the environment variable WEBSITES_ENABLE_APP_SERVICE_STORAGE
as True
. Remember, it just adds the persisting volume. So you need to copy file seed.sql to the path through FTP/FTPS. For more details, see Add persistent storage.
User contributions licensed under CC BY-SA 3.0