Changing Dockerfile's build context directory without changing .dockerignore position

202 views Asked by At

I want to include files outside of Docker's build context using context change and so that .dockerignore works. But to work correctly, I need to move .dockerignore to the updated build context directory. How to avoid it?

Works:

$ ls -a
.  ..  Dockerfile  .dockerignore  sourses  ulala
$ sudo docker build -t docker_test -f Dockerfile .
$ sudo docker run -it docker_test bash
# ls
Dockerfile  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  sourses  srv  sys  tmp  usr  var

Don't work:

$ ls -a
.  ..  Dockerfile  .dockerignore  sourses  ulala
$ mkdir dock_dir
$ cd dock_dir/
$ cp ../Dockerfile ./Dockerfile
$ rm ../Dockerfile
$ cp ../.dockerignore ./.dockerignore
$ rm ../.dockerignore
$ sudo docker build -t docker_test -f Dockerfile ..
$ sudo docker run -it docker_test bash
# ls
bin  boot  dev  dock_dir  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  sourses  srv  sys  tmp  ulala  usr  var

Works, but I don't want it

$ ls -a
.  ..  Dockerfile  .dockerignore  sourses  ulala
$ mkdir dock_dir
$ cd dock_dir/
$ cp ../Dockerfile ./Dockerfile
$ rm ../Dockerfile
$ sudo docker build -t docker_test -f Dockerfile ..
$ sudo docker run -it docker_test bash
# ls
Dockerfile  bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  sourses  srv  sys  tmp  usr  var

Dockerfile:

FROM debian:latest
ADD  . .

.dockerignore:

**/ulala/**/*
**/ulala
0

There are 0 answers