Betzen Ben Betzen Ben - 1 year ago 150
Bash Question

How to Login,Tag, Push an Docker Image to AWS using shell script called from java

Hello I am trying to push a docker image via shell command programming to AWS EC2 Container Service. But I am having trouble doing that and I am getting the following error messages:

error getting credentials - err: exec: "docker-credential-osxkeychain": executable file not found in $PATH, out: ``
no basic auth credentials

This error message is returned from my java class. If I start the shell script form the terminal i am having no problems only if I start it form my java class. I created an config.js file an added osxkeychain to it because i thought this might save the problem.

This is my Dockerfile:

FROM java:7
COPY . /Users/betzenben/Desktop/OGC/Projects/Getting_started/Docker/Directory
WORKDIR /Users/betzenben/Desktop/OGC/Projects/Getting_started/Docker/Directory
RUN javac
CMD ["java", "Time_app"]
Run : ~/Users/betzenben/Desktop/OGC/Projects/Getting_started/Docker/Directory/config.json

And this my config.json file

"apps": [
"credsStore": "osxkeychain"

And just in case it is needed my shell script code and my java class that calls the shell script.


echo “test1”
getLoginKey+="$(/usr/local/bin/aws ecr get-login --no-include-email --region us-west-2)"
echo “test2”
echo "${getLoginKey}"

executeLoginKey="$(eval $getLoginKey)"
echo “test3”
sleep 2
echo "${executeLoginKey}"

tagImage="$(/usr/local/bin/docker tag time_app:latest"
pushImage="$(/usr/local/bin/docker push"
echo “test4”
sleep 5
echo "${pushImage}"
echo "Image Pushed"

Java Code:


public class Main {

public static void main(String[] args) throws InterruptedException, IOException {

Process p1 = Runtime.getRuntime().exec("chmod +x /Users/betzenben/Desktop/");

BufferedReader stdInput1 = new BufferedReader(new InputStreamReader(p1.getInputStream()));
BufferedReader stdError1 = new BufferedReader(new InputStreamReader(p1.getErrorStream()));

String s1 = null;
while ((s1 = stdInput1.readLine()) != null) {
while ((s1 = stdError1.readLine()) != null) {

Process p = Runtime.getRuntime().exec("/Users/betzenben/Desktop/");

BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

String s = null;
while ((s = stdInput.readLine()) != null) {
while ((s = stdError.readLine()) != null) {

Answer Source

In your file change




If that doesn't work then try below code in java

Runtime.getRuntime().exec(new String[]{"/bin/bash","-lc", "/Users/betzenben/Desktop/"});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download