Error while executing Docker in Docker



Hello team,

I have written below configuration to test in Circle CI.

version: 2
    working_directory: /app
      #- image:18.06.0-ce-git
      - image: docker:17.05.0-ce-git
      - checkout
      - setup_remote_docker
      - run:
          name: Install dependencies
          command: |
            apk add --no-cache \
            apk --no-cache add curl
            pip install wget
            pip install \
              docker-compose==1.12.0 \
      - 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 .
      - 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

javac: file not found: 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.



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 .
[node1] (local) root@ ~/GroovyLearning
$ ls -la Ad
Add.class         AddTests.groovy
[node1] (local) root@ ~/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.



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
      #- image:18.06.0-ce-git
      - image: circleci/openjdk:8-jdk-browsers
      - 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' 



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