Failing to test Java program using Docker in CircleCI

Hello team,

I am testing java program using below circle configuration.

version: 2
jobs:
  build:
    working_directory: /app
    docker:
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - run:
          name: Pulling java docker.
          command: |
            docker pull java:7
      - run:
          name: Create class file using java docker.
          command: |
            docker run --rm -v"$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac -d . JavProg.java
      - run:
          name: Compiling and Executing java class files using java docker.
          command: |
            docker run --rm -v"$PWD":/usr/src/myapp -w /usr/src/myapp java:7 java learnjava.JavProg
      - run:
          name: Displaying java class.
          command: |
            docker run --rm -v"$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javap learnjava.JavProg

My Project repository link : https://github.com/hemanth22/MyJavaLearning/tree/hemanth22-patch-2

Can you please check and advice.

Thanks and regards,
Hemanth.

Hello halfer,

I have updated my post with code formatting.

Can you please advice how why it is failing when use docker repo

Thanks,
Hemanth

May we see the console output for the failing step? Please paste it here, in a formatted text block. Thanks!

(If all you are doing with Docker is compiling and running a Java program, you may find it easier to just install Java into your VM).

Hello Halfer,

I am getting below error in Pulling java docker step .
Please find the link of circle ci output here: https://circleci.com/gh/hemanth22/MyJavaLearning/39?utm_campaign=vcs-integration-link&utm_medium=referral&utm_source=github-build-link

#!/bin/sh -eo pipefail
docker pull java:7
Warning: failed to get default registry endpoint from daemon (Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system default: https://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Exited with code 1

After your checkout step, try some commands to see if Docker is running. Let us know what you get with this:

ps aux | grep docker

Also, try connecting with Docker using a privileged user, and show us what that gives you:

sudo docker ps

Hello halfer,

Issue us resolved after changing config as below.

 version: 2
jobs:
  build:
working_directory: /app
docker:
  - image: java:7
steps:
  - checkout
  - run: javac -d . JavProg.java
  - run: java learnjava.JavProg
  - run: javap learnjava.JavProg

Please mark this issue as resolved.

Thanks,
Hemanth

Nice work :smiley:

You can do that yourself, by clicking the “solved” icon in the appropriate post. You do not need to add [solved] edits to the title.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.