dotnet / dotnet/Docker.DotNet

Unable to run a docker container from .NET client by passing environment variable

Open
#407 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
416
PR merge metrics
No merged PRs in 30d

Description

**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:**
1. Docker.NET C# Code

strUrl = "npipe://./pipe/docker_engine"
DockerClient client = new DockerClientConfiguration(new Uri(strUrl)).CreateClient();
IList partitionKeys = 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);
}

2. 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" ]


3. Docker shell command

docker run -e PARTITION_KEY='NA' -t xxxxx/azureconnect:2


4. 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
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.