Error while executing Docker in Docker

Hello team,

I have written below configuration to test in Circle CI.

version: 2
jobs:
  build:
    working_directory: /app
    docker:
      #- image:18.06.0-ce-git
      - image: docker:17.05.0-ce-git
    steps:
      - checkout
      - setup_remote_docker
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache \
              py-pip=9.0.0-r1
            apk --no-cache add curl
            pip install wget
            pip install \
              docker-compose==1.12.0 \
              awscli==1.11.76
      - run: echo "Pulling docker's"
      - run: docker pull java:7
      - run: docker pull groovy
      - run: echo "Docker pull complete."
      - run: docker run --rm -v"$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac -d . Add.java
      - run: docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy groovy AddTests.groovy

But is throwing below error.

#!/bin/sh -eo pipefail docker run --rm -v"$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac Add.java

javac: file not found: Add.java Usage: javac <options> <source files> use -help for a list of possible options Exited with code 2

Can please check and advice what is wrong in the code. and why it has thrown error.

Thanks,
Hemanth.

I have tested same command in play with docker.

I could see result is good .

Playwithdocker result

$ docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp java:7 javac -d . Add.java
[node1] (local) root@192.168.0.18 ~/GroovyLearning
$ ls -la Ad
Add.class        Add.java         AddTests.groovy
[node1] (local) root@192.168.0.18 ~/GroovyLearning
$ docker run --rm -v "$PWD":/home/groovy/scripts -w /home/groovy/scripts groovy groovy AddTests.groovy
.
Time: 0.081

OK (1 test)

Then accordingly i have updated in circle ci configuration, even though it is thowing error.
Can you please have a check.

Thanks,
Hemanth.

There’s a couple of things:

  • Your first -v volume statement is missing a space after the switch, so I wonder if this might be a syntax error
  • But, more importantly, on-host volumes don’t work in CircleCI. That’s because CircleCI intervenes in your Docker system to spin containers up on remote machines, and volumes don’t work across LAN connections. Search for “Docker volume” in this forum to see plenty of info about this (it happened to me too).

You can solve this in several ways:

  • Build your own Docker image that inherits from java:7 or groovy and copies in the files they need
  • If you need more than one container to communicate, run containers inside Docker Compose

Thank you @halfer.

When i have changed script as below, it is working fine.

version: 2
jobs:
  build:
    docker:
      #- image:18.06.0-ce-git
      - image: circleci/openjdk:8-jdk-browsers
    steps:
      - checkout
      - run:
          name: Installing Groovy.
          command: 'sudo apt-get install groovy'
      - run:
          name: Creating InsufficientFundsException.
          command: 'groovyc InsufficientFundsException.groovy'
      - run:
          name: Creating InterestRateService class.
          command: 'groovyc InterestRateService.groovy'
      - run:
          name: Executing Groovy test case.
          command: 'groovy BankAccountTests.groovy' 

Regards,
Hemanth.

1 Like

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