Skip to content

Instantly share code, notes, and snippets.

@MatMoore
Last active June 21, 2019 13:05
Show Gist options
  • Save MatMoore/686bd8e39ff2de85745e9ee9cb7b157b to your computer and use it in GitHub Desktop.
Save MatMoore/686bd8e39ff2de85745e9ee9cb7b157b to your computer and use it in GitHub Desktop.
Remote docker problems

Problem

I want to build a container inside my circleci build and mount files from the outer build environment.

Running this docker command works outside of circleci, but not on circleci (when using the docker exectutor with setup_remote_docker).

circleci@07b4d1bb33c0:/tmp/workspace$ docker run -p 7001:7001 -p 9002:9002 -v $(pwd):/u01/oracle/properties store/oracle/weblogic:12.2.1.3
Domain Home is:  /u01/oracle/user_projects/domains/base_domain
awk: warning: command line argument `/u01/oracle/properties/domain.properties' is a directory: skipped
The domain username is blank.  The Admin username must be set in the properties file.

Why is domain.properties a directory?

It's a file in the outer container:

circleci@07b4d1bb33c0:/tmp/workspace$ cat domain.properties
username=myadminusername
password=myReally5trong4dminP4a55w0rd

Looking inside the inner container:

circleci@07b4d1bb33c0:/tmp/workspace$ docker run -it -p 7001:7001 -p 9002:9002 -v $(pwd):/u01/oracle/properties --entrypoint /bin/bash store/oracle/weblogic:12.2.1.3
[oracle@c7938a223f75 ~]$ ls /u01/oracle/properties/
domain.properties  pui
[oracle@c7938a223f75 ~]$ ls /u01/oracle/properties/domain.properties/
[oracle@c7938a223f75 ~]$ ls /u01/oracle/properties/domain.properties/
[oracle@c7938a223f75 ~]$ ls /u01/oracle/properties/domain.properties/
[oracle@c7938a223f75 ~]$ exit

It's definitely a directory here.

Answer

It turns out if you wanna run docker inside your docker you can't mount directories. https://circleci.com/docs/2.0/building-docker-images/#mounting-folders

Workarounds

using --volumes-from

This is what circleci tell you to do

- run: |
    # create a dummy container which will hold a volume with config
    docker create -v /cfg --name configs alpine:3.4 /bin/true
    # copy a config file into this volume
    docker cp path/in/your/source/code/app_config.yml configs:/cfg
    # start an application container using this volume
    docker run --volumes-from configs app-image:1.2.3

In my case I ran something like this:

      - run:
          name: Start weblogic in docker
          command: |
                # Create a dummy container which will hold the volumes
                docker create -v /u01/oracle/properties -v /workspace -v /externalProperties --name configs store/oracle/weblogic:12.2.1.3 /bin/true

                # Copy the required files into the volumes
                docker cp /tmp/workspace/domain.properties configs:/u01/oracle/properties/domain.properties
                docker cp /tmp/workspace/pui/build/resources configs:/externalProperties           # Configuration read by the application
                docker cp /tmp/workspace/pui/gradleBuild/libs/ccms.war configs:/workspace/ccms.war # The application
                docker cp /tmp/workspace/app-deploy.py configs:/workspace/app-deploy.py            # WLST script to deploy the war file in weblogic

                # Start the weblogic container with these volumes
                docker run -p 7001:7001 -p 9002:9002 --volumes-from configs \
                  store/oracle/weblogic:12.2.1.3
          background: true

This start up. However - the port forwarding doesn't work because the remote docker environment is seperated from the job that runs it. That is very annoying as I am spinning up the service to test it, and test tools are not part of that image.

Using the machine executor

You can use the machine executor (as suggested by people here: https://discuss.circleci.com/t/why-circleci-2-0-does-not-support-mounting-folders/11605)

But I still ran into problems with the mounted directory:

[oracle@239828a5dda7 ~]$ ls -l /u01/oracle/properties
ls: cannot open directory /u01/oracle/properties: Permission denied
[oracle@239828a5dda7 ~]$ ls -l /u01/oracle
total 48
drwxr-x--- 11 oracle oracle 4096 May 28 20:33 OPatch
drwxr-x---  5 oracle oracle 4096 May 28 20:34 cfgtoollogs
drwxr-x---  5 oracle oracle 4096 May 28 20:32 coherence
-rw-rw-r--  1 oracle oracle 3133 May 28 20:30 create-wls-domain.py
-rwxrwxr-x  1 oracle oracle 2430 May 28 20:30 createAndStartEmptyDomain.sh
drwxr-x--- 19 oracle oracle 4096 May 28 20:34 inventory
-rw-r-----  1 oracle oracle  126 May 28 20:33 oraInst.loc
drwxr-x--- 11 oracle oracle 4096 May 28 20:33 oracle_common
drwxr-x---  8 oracle oracle 4096 May 28 20:33 oui
drwx------  3   1001   1002 4096 Jun 20 15:57 properties
-rwx------  1 oracle oracle   10 May 28 20:32 root.sh
drwxr-x---  7 oracle oracle 4096 May 28 20:33 wlserver

Now the mounted directory is owned by some non existent user? I abandoned this approach.

Create a dockerfile that wraps the one I'm using

Rather than copy those files into a dummy container, I could extend the image and run those copy commands in a dockerfile. This seems better as it gives me an image I can run on any environment, rather than extra code in my CircleCI configuration which can't be reused anywhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment