.dockerignore not ignoring docker-compose.yml

2.6k views Asked by At

I've been reading through the posts here and all over, but still I don't get why my docker-compose files are not being ignored.

They are at my projects root directory. Along with my .env, package.json and everything else.

So, here is my .dockerignore file:

.git
docker*
docker-compose.yml
node_modules
.env
*.log
.gitignore
yarn.log
.dockerignore
.editorconfig
README.md
LICENSE
.vscode

I have tried different things, such as: docker-compose.yml* , *docker-compose.yml and *docker-compose

Still I get this file pushed over to the remote branch.

Any different approaches?

2

There are 2 answers

1
Khali On

If by "Still I get this file pushed over to the remote branch", you mean you are trying to gitignore that file then you can remove it using

git rm --cached docker-composer.yml

0
F1Linux On

Problem Restated:

It appears that you're getting .gitignore confused with .dockerignore:

The later file tells Docker what files to ignore during the build of a Docker image. .dockerignore has nothing to do with Git pushes to upstream branches.

Solution:

Add the docker-compose.yml file(s) to your .gitignore file if you don't want Git tracking the file(s).

Don't delete .dockerignore if you want it read during builds.