Docker Community Forums

Share and learn in the Docker community.

Copy static files from Docker container to non empty named volume


(Artem Innokentiev) #1

I wanna copy new static files from Docker container via named volume to nginx container that has old static.

Prerequisites:

Host machine directory tree:

.
├── data
│   ├── bar.2.css
│   └── foo.2.js
├── docker-compose.yml
├── Dockerfile

Dockerfile:

FROM busybox:latest
COPY data /data

docker-compose.yml:

version: '3'

services:
  static:
    image: 'myimage'
    volumes: 
      - 'myvolume:/data'

  nginx:
    image: 'nginx'
    volumes: 
      - 'myvolume:/data'

volumes:
  myvolume:

Directory tree of named volume myvolume with old static:

    .
    ├── bar.1.css
    └── foo.1.js

Sequence of steps:

  1. Build myimage with Dockerfile: docker build -t myimage .

  2. Check new static files in myimage: docker run myimage ls /data

    bar.2.css
    foo.2.js

  3. Run: docker-compose up -d --build static

In my mind it must rebuild service static and overwrite old static files. But it did’t. Why and how to fix it? Also, what is a better approach?