Reputation: 75686
Here is my docker-compose.yml
version: "3.5"
services:
api:
container_name: upvotocracy-api
restart: always
build: .
env_file: .env
ports:
- "127.0.0.1:8537:8537"
- "127.0.0.1:9228:9229"
links:
- mongo
volumes:
- ./index.js:/usr/src/app/index.js
- ./.env:/usr/src/app/.env
networks:
- upvotocracy-network
mongo:
container_name: upvotocracy-mongo
restart: always
image: mongo:latest
env_file: .env
volumes:
- ./mongo_data:/data/db
ports:
- "127.0.0.1:28016:27017"
networks:
- upvotocracy-network
redis:
image: redis
restart: always
container_name: upvotocracy-cache
ports:
- "127.0.0.1:6381:6379"
networks:
- upvotocracy-network
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.6.2
container_name: upvotocracy-es01
restart: always
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- cluster.initial_master_nodes=es01
- bootstrap.memory_lock=true
- action.auto_create_index=+*
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data01:/usr/share/elasticsearch/data
ports:
- 127.0.0.1:9201:9200
networks:
- upvotocracy-network
networks:
upvotocracy-network:
name: upvotocracy-network
volumes:
mongo_data: {}
data01:
driver: local
It only works when I run docker-compose up as root, otherwise I get a permission denied error on ./mongo_data
directory which is owned by 999:ubuntu
Pulling mongo ... done
Pulling api ... done
Pulling redis ... done
Pulling es01 ... done
mongo uses an image, skipping
redis uses an image, skipping
es01 uses an image, skipping
Building api
Traceback (most recent call last):
File "bin/docker-compose", line 6, in <module>
File "compose/cli/main.py", line 72, in main
File "compose/cli/main.py", line 128, in perform_command
File "compose/cli/main.py", line 303, in build
File "compose/project.py", line 403, in build
File "compose/project.py", line 385, in build_service
File "compose/service.py", line 1106, in build
File "site-packages/docker/api/build.py", line 160, in build
File "site-packages/docker/utils/build.py", line 30, in tar
File "site-packages/docker/utils/build.py", line 49, in exclude_paths
File "site-packages/docker/utils/build.py", line 214, in rec_walk
File "site-packages/docker/utils/build.py", line 214, in rec_walk
File "site-packages/docker/utils/build.py", line 184, in rec_walk
PermissionError: [Errno 13] Permission denied: '/home/ubuntu/data/www/coupondealsavings.com/api/mongo_data/diagnostic.data'
[10551] Failed to execute script docker-compose
Starting coupondeals-mongo ... done
Starting coupondeals-cache ... done
Starting coupondeals-es01 ... done
Starting coupondeals-api ... done
Connection to xxx closed.
Upvotes: 4
Views: 5542
Reputation: 75686
For me I just had to add ./mongo_data
to .dockerignore
and the Dockerfile would ignore this directory while building api
.
I did this for all my volumes and things work fine now, no permission errors.
Upvotes: 10
Reputation: 111
I had the same problem. I assume that you didn't have this permission error at your first time of docker-compose up. The The file "mongo_data/diagnostic.data" did not exist either. The mongo container will create the file when starting, and the file belongs to a user, it's 999:root in my case(postgres).
drwx------ 19 999 root 4096 Jun 4 12:19 postgres-data/
Your api container has the current directory as the build context. The user who builds the docker is your host user, it has to not be 999. So when you docker-compose up would have the permission denied. You can create a .dockerignore file in the context folder, the content is:
mongo_data
You have to add other folders in this file in the volumes of other containers.
Upvotes: -1