Volume share from container to host docker-compose

Gustavo Barbosa

I'm trying to share data between container and host. So I just want to do this to store container files. The data must be shared from a container to host.

My docker-compose.yml

version: "3.3"
services:
  django:
    image: python:slim
    volumes:
      - type: volume
        source: ./env
        target: /usr/local/lib/python3.6/site-packages
        volume:
          nocopy: true
      - ./src:/usr/src/app
    ports:
      - '80:80'
    working_dir: /usr/src/app
    command: bash -c "pip install -r requirements.txt && python manage.py runserver"

When I run docker throws this:

ERROR: for django Cannot create container for service django: invalid bind mount spec "/Users/gustavoopb/git/adv/env:/usr/local/lib/python3.6/site-packages:nocopy": invalid volume specification: '/Users/gustavoopb/git/adv/env:/usr/local/lib/python3.6/site-packages:nocopy': invalid mount config for type "bind": field VolumeOptions must not be specified ERROR: Encountered errors while bringing up the project.

https://docs.docker.com/compose/compose-file/#long-syntax-3

Gustavo Barbosa

My problem was keeping the python env when my container goes down. To do this I need to share the env inside of the container to host. I tried the docker docs suggestion, but it wasn't working.

volume: 
    nocopy: true

My solution: I create a named container.

version: "2"

services:
  django:
    image: python:2.7
    command: bash -c "pip install -r requirements.txt && python manage.py collectstatic --no-input && python manage.py migrate && python manage.py runserver 0.0.0.0:80"
    env_file:
      - .env
    volumes:
      - .:/app
      - env:/Library/Python/2.7/site-packages
    links:
      - database
    ports:
      - "8000:80"
    working_dir: /app

volumes:
  env:

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Share directory or volume with container from host

Dockerfile COPY from host to container works, but when docker-compose.yml uses volume, the file in container not visible to host

How to mount volume from container to host in Docker?

Docker (Dockerfile): Share a directory from host to container

Share folder from docker container to host

How to share file from docker container to host

Docker compose - share volume Nginx

docker-compose: how to map a file from a container into a volume

How to Share a Docker-Compose Volume in Distributed Cassandra Container using Docker

How to isolate docker container from the host network (docker-compose)

Docker - Share volume between containers in docker compose

Running docker on Ubuntu: mounted host volume is not writable from container

How to find volume files from host while inside docker container?

Persisting the images from Docker Container to host named volume

Can user privilege of docker container impact permission of host machine on mounted volume in docker-compose.yml?

Share Docker container through local network and access to it from an another host

How to directly mount NFS share/volume in container using docker compose v3

docker-compose, How to share volume

Zeroconf discovery from docker-compose container to LAN host

Copy file from container to host using Dockerfile or Docker-compose

Access mariadb docker-compose container from host-machine

How is docker able to mount a volume from docker client into a docker container running on docker host?

Docker compose problem with volume container attachment

starting postgres container with persistant volume [docker compose]

Share Existing Host Directory with Docker Container?

How to copy files from docker container to host using docker-compose in docker-machine

Docker / Docker-compose volume fill & share issue

Hot reload fails when files are changed from the host mapped volume in Docker-compose

Make a container accessible to the host with docker-compose