Yes, you can; you can even throw the .dockerignore
itself in there!
You're likely doing something else incorrect - possibly in the wrong directory?
Directory listing:
➜ ls -la
total 16
drwxr-xr-x 4 tj wheel 128 Nov 30 13:42 .
drwxrwxrwt 7 root wheel 224 Nov 30 13:42 ..
-rw-r--r-- 1 tj wheel 26 Nov 30 13:41 .dockerignore
-rw-r--r-- 1 tj wheel 28 Nov 30 13:42 Dockerfile
Content of files:
➜ cat .dockerignore
.dockerignore
Dockerfile
➜ test_docker_ignore cat Dockerfile
FROM ubuntu:16.04
ADD . .
Build it once; specifying --no-cache
to be verbose:
➜ docker build -t test --no-cache .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM ubuntu:16.04
---> 20c44cd7596f
Step 2/2 : ADD . .
---> 4d8ded297954
Successfully built 4d8ded297954
Successfully tagged test:latest
Add something to the Dockerfile
and rebuild:
The build will use the cache as it ignores the changes made to the Dockerfile
➜ echo "# A Test Comment" >> Dockerfile
➜ docker build -t test .
Sending build context to Docker daemon 3.072kB
Step 1/2 : FROM ubuntu:16.04
---> 20c44cd7596f
Step 2/2 : ADD . .
---> Using cache
---> 4d8ded297954
Successfully built 4d8ded297954
Successfully tagged test:latest