I have written a gradle task buildDocker in my build.gradle file as follows:

```
task buildDocker(type: Docker, dependsOn: copyJar) {
    push = false
    baseImage "openjdk:8u151"
    println System.getenv('AWS_ACCESS_KEY_ID')
    println System.getenv('AWS_SECRET_ACCESS_KEY')
    setEnvironment('AWS_ACCESS_KEY_ID',System.getenv('AWS_ACCESS_KEY_ID'))
    setEnvironment('AWS_SECRET_ACCESS_KEY',System.getenv('AWS_SECRET_ACCESS_KEY'))
    runCommand("mkdir myProject")
    addFile("myProject-0.0.jar","myProject/")
    workingDir("/myProject")
    runCommand("unzip -q myProject-0.0.jar")
    exposePort(8888)
    entryPoint(["java","-XX:+UnlockExperimentalVMOptions","- 
XX:+UseCGroupMemoryLimitForHeap","-XX:MaxRAMFraction=1","-XshowSettings:vm","-cp", 
"/myProject-config:.","org.springframework.boot.loader.JarLauncher"])
}

```

When I build the image by running the task I am able to see the println outputs in the terminal. But when I run the image, I keep getting the following exception:

```
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'simpleMessageListenerContainer' defined in class path resource [org/springframework/cloud/aws/messaging/config/annotation/SqsConfiguration.class]: Invocation of init method failed; nested exception is com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.profile.ProfileCredentialsProvider@46244e65: profile file cannot be null]

```

```
Caused by: com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [com.amazonaws.auth.profile.ProfileCredentialsProvider@46244e65: profile file cannot be null]

```

I have also tried setting the environment variables directly in the run statement by using the -e parameters in the run command and by mounting my ~/.aws/credentials file to the docker container , but with those also, I get the same exception.

EDIT1: here's the docker run command using the -e flags :

```
docker run -e AWS_ACCESS_KEY_ID=XXXX -e AWS_SECRET_ACCESS_KEY=XXXX --link mysql --name myapp <imageName>

```

Also, put the credentials as key value pairs in a file-env.list and tried this:

```
docker run --env-file env.list -v --link mysql --name myapp <imagename>

```