Wednesday, June 15, 2022

Docker / docker-compose / Kubernetes - add volume

 You can think docker-compose as container orchestrator. Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Here, I just created a simple docker-compose file to add a mounted volume.

services: 2 myapp: 3 image: image-name:0.0 4 build: 5 context: . 6 volumes: 7 - ./:/app

And when you locally debug or run your docker image, you can just simply run:

1docker-compose build

2docker run -it image-name:0.0

Remember, be sure to use docker-compose down to remove network connection.

When you orchestrate the docker through Argo, by default, Docker can get output artifacts/parameters from the base layer (e.g. /tmp), so we can mount volumes onto the pod. The easiest way to do this is to use as emptyDir volume. (This is only needed for output artifacts/parameters. Input artifacts/parameters are automatically mounted to an empty-dir if needed).

(Ref: https://argoproj.github.io/argo-workflows/empty-dir/)

- name: xxx-template 2 metadata: 3 annotations: 4 sidecar.istio.io/inject: 'false' 5 container: 6 image: image-name:latest 7 imagePullPolicy: Always 8 command: ["python", "scraper/__main__.py"] 9 volumeMounts: 10 - name: downloads 11 mountPath: /output 12 volumes: 13 - name: downloads 14 emptyDir: { }

No comments:

Post a Comment