2

There's something I'm not quite understanding about how volumes work in Docker. I have two separate images: one that is used to build a javascript bundle, and one that is used to deploy it to S3. I am doing this all on Codeship, but I believe their codeship-steps.yml files are meant to be docker-compose compatible. So I don't think this is specific to Codeship, but I might be wrong.

I am mounting a volume in both containers, and am able to read an artifact from the "read-artifact" container that was written in the "write-artifact" container like this:

Scenario 1

# codeship-steps.yml
- name: write-artifact
  service: write-artifact
  command: /bin/bash -c "echo hi > /styleguide/hello.txt"

- name: read-artifact
  service: read-artifact
  command: cat /styleguide/hello.txt # this reads "hi"


# codeship-services.yml
write-artifact:
  build:
    context: .
    dockerfile: Dockerfile
  volumes:
    - ./tmp:/styleguide

read-artifact:
  image: busybox
  volumes_from:
    - read-artifact

I can read the contents of the file correctly from the second container.

However, what I want is to run an npm script in the first container, and have access to those built assets from the seconds container. But when running an npm script that bundles assets to that same directory, the directory shows up empty.

Scenario 2

# codeship-steps.yml
- name: write-artifact
  service: write-artifact
  command: /bin/bash -c "npm run build"

- name: read-artifact
  service: read-artifact
  command: ls -a /styleguide # this is empty


# codeship-services.yml (same as scenario 1)
write-artifact:
  build:
    context: .
    dockerfile: Dockerfile
  volumes:
    - ./tmp:/styleguide

read-artifact:
  image: busybox
  volumes_from:
    - read-artifact

I would love to be able to have access to the built assets in the second container, so that I can just use that container to deploy, while just using the first container to build.

Tyler
  • 829
  • 11
  • 26

0 Answers0