Murphy Meng
Murphy Meng

Reputation: 237

How to specify volume for docker container in CircleCI configuration?

I did not manage to find out how to mount volume of docker image in config.yml for integrating with CircleCI.

Official document gives those variables for container usage, entry point, command, etc., but none about volume mounting.

The scenario is, the building of my project requires two docker containers, the main container and the other container for service foo. To use the service foo, I need expose some artifacts generated in earlier steps to foo container and do some next steps.

Anyone has idea whether I can do that?

Upvotes: 0

Views: 1684

Answers (1)

Sergiu
Sergiu

Reputation: 3185

As taken from CircleCI documentation:

Mounting Folders
It’s not possible to mount a folder from your job space into a container in Remote Docker (and vice versa). But you can use docker cp command to transfer files between these two environments. For example, you want to start a container in Remote Docker and you want to use a config file from your source code for that:

- run: |
    # creating dummy container which will hold a volume with config
    docker create -v /cfg --name configs alpine:3.4 /bin/true
    # copying config file into this volume
    docker cp path/in/your/source/code/app_config.yml configs:/cfg
    # starting application container using this volume
    docker run --volumes-from configs app-image:1.2.3
In the same way, if your application produces some artifacts that need to be stored, you can copy them from Remote Docker:

- run: |
    # starting container with our application
    # make sure you're not using `--rm` option otherwise container will be killed after finish
    docker run --name app app-image:1.2.3

- run: |
    # once application container finishes we can copy artifacts directly from it
    docker cp app:/output /path/in/your/job/space

Upvotes: 3

Related Questions