The Problem
Hi I'm new to Docker. I want to ignore some files and directories using .dockerignore in my Django project. In the beginning, no files were ignored , then I searched in stackoverflow and found that its because of the volumes in docker-compose.yml, so I commented it out. But now some of the files and directories are getting ignored but some are not( pycache , db.sqlite3 ). I went through a lot of questions but couldn't find any solution.
Project structure
-src
--coreapp
---migrations
---__init__.py
---__pycache__
---admin.py
---apps.py
---models.py
---tests.py
---views.py
---tests.py
--admin.json
--db.sqlite3
--manage.py
-.dockerignore
-.gitignore
-docker-compose.yml
-Dockerfile
-Procfile
-README.md
-requirements.txt
-runtime.txt
Dockerfile
FROM python:3.7
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /code/requirements.txt
RUN pip install -r /code/requirements.txt
COPY . /code/
WORKDIR /code/
EXPOSE 8000
docker-compose.yml
version: '3'
services:
db:
image: postgres
web:
build: .
command: bash -c "python src/manage.py runserver 0.0.0.0:8000"
# volumes:
# - .:/code
ports:
- "8000:8000"
depends_on:
- db
.dockerignore
# Byte-compiled / optimized / DLL files
__pycache__/
**/migrations
src/media
src/db.sqlite3
Procfile
.git
Commands
# build image
sudo docker-compose up --build
# to enter container
sudo docker exec -it [container id] bash
# to check ignored files inside the container
ls
Expected output
# Byte-compiled / optimized / DLL files
__pycache__/ # ignored
**/migrations # ignored
src/media # ignored
src/db.sqlite3 # ignored
Procfile # ignored
.git # ignored
Original Output
# Byte-compiled / optimized / DLL files
__pycache__/ # NOT ignored
**/migrations # ignored
src/media # ignored
src/db.sqlite3 # NOT ignored
Procfile # ignored
.git # ignored
Attempts
__pycache__/
**/__pycache__
**/*__pycache__
**/*__pycache__*
**/*__pycache__/
**/__pycache__/
*/db.sqlite3
db.sqlite3