Unable to run a docker container from .NET client by passing environment variable
Output of dotnet --info:
.NET Core SDK (reflecting any global.json): Version: 2.1.403 Commit: 04e15494b6
Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\2.1.403\
Host (useful for support): Version: 2.1.5 Commit: 290303f510
.NET Core SDKs installed: 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.202 [C:\Program Files\dotnet\sdk] 2.1.402 [C:\Program Files\dotnet\sdk] 2.1.403 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs: https://aka.ms/dotnet-download
What version of Docker.DotNet?: version 3.125.2
Steps to reproduce the issue:
-
Docker.NET C# Code
strUrl = "npipe://./pipe/docker_engine" DockerClient client = new DockerClientConfiguration(new Uri(strUrl)).CreateClient();
IListpartitionKeys = new List { "NA","SA","APAC","AFR","EUR","CHN" }; foreach (var item in partitionKeys) { var cntrParameters = new CreateContainerParameters(new Config { Image = "xxxx/xxxx:2", Env = new List
{ string.Format("PARTITION_KEY = '{0}'", item) }, //Env = new List { "PARTITION_KEY = 'NA'" }, }); var createCntrParametersResponse = await client.Containers.CreateContainerAsync(cntrParameters); var ContainerId = createCntrParametersResponse.ID; var strtCntrParameters = new ContainerStartParameters(); var strtCntrParametersResponse = await client.Containers.StartContainerAsync(ContainerId, strtCntrParameters); } -
Docker file
FROM python:3.6 ADD azureconnect.py RUN pip install numpy RUN pip install pandas RUN pip install LightGBM RUN pip install pymssql RUN pip install matplotlib RUN pip install random2 RUN pip install azure-cosmosdb-table CMD [ "python", "./azureconnect.py" ] -
Docker shell command
docker run -e PARTITION_KEY='NA' -t xxxxx/azureconnect:2 -
Python code running in docker
from azure.cosmosdb.table.tableservice import TableService from azure.cosmosdb.table.models import Entity import numpy as np import LightGBM as lgb import os import random table_service = TableService(account_name="*******",account_key="******;EndpointSuffix=core.windows.net") partitionkey = os.environ['PARTITION_KEY'] #partitionkey = 'NORTH_AMERICA' task001 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(0, 1000)), 'description' : 'step1', 'priority' : 400} task002 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(1000, 2000)), 'description' : 'step2', 'priority' : 100} task003 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(2000, 3000)), 'description' : 'step3', 'priority' : 400} task004 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(3000, 4000)), 'description' : 'step4', 'priority' : 100} task005 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(4000, 5000)), 'description' : 'step5', 'priority' : 100} task006 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(5000, 6000)), 'description' : 'step6', 'priority' : 400} task007 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(6000, 7000)), 'description' : 'step7', 'priority' : 100} task008 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(7000, 8000)), 'description' : 'step8', 'priority' : 400} task009 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(8000, 9000)), 'description' : 'step9', 'priority' : 100} task0010 = {'PartitionKey': partitionkey, 'RowKey': str(random.randint(9000, 10000)), 'description' : 'step10', 'priority' : 100} table_service.insert_entity('dockerlogger',task001) table_service.insert_entity('dockerlogger',task002) table_service.insert_entity('dockerlogger',task003) table_service.insert_entity('dockerlogger',task004) table_service.insert_entity('dockerlogger',task005) table_service.insert_entity('dockerlogger',task006) table_service.insert_entity('dockerlogger',task007) table_service.insert_entity('dockerlogger',task008) table_service.insert_entity('dockerlogger',task009) table_service.insert_entity('dockerlogger',task0010)
docker version
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:13:06 2019
OS/Arch: linux/amd64
Experimental: false
What actually happened?:
Docker logs CONTAINERID
Traceback (most recent call last):
File "./azureconnect.py", line 9, in <module>
partitionkey = os.environ['PARTITION_KEY']
File "/usr/local/lib/python3.6/os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'PARTITION_KEY'
What did you expect to happen?: On running the code the azure table storage needs to be inserted with new 10 records. The same docker runs perfectly from 'cmdlime' but throws an error running from docker.net.
Additional information: If this is not docker issue atleast help me in fixing this issue I tried all possible scenarios I could not find proper resources in web. I checked Issues #308, #136
Have you tried removing spaces in PARTITION_KEY = '{0}' to make PARTITION_KEY='{0}'?
I seem to remember this working for me.
Any help on this??
Have you tried removing spaces in
PARTITION_KEY = '{0}'to makePARTITION_KEY='{0}'? I seem to remember this working for me.
I tried It is not working for me
@KumaranHobbyDeveloper did you find a fix? Same issue here.
How do you set the environment? KEY=VALUE without quotes work fine. I have no issue with the latest version.
var runParams = new CreateContainerParameters
{
Name = "accbackup",
Env = new List<string>(){$"AWS_ACCESS_KEY_ID={AWS_ACCESS_KEY_ID}",$"AWS_SECRET_ACCESS_KEY={AWS_SECRET_ACCESS_KEY}",$"S3_BUCKET_NAME={volume}"},
Cmd = null,
ArgsEscaped = false,
....
}
Nevermind, I did a docker inspect <container> and it shows something else. I think my code is overriding the settings elsewhere.