Docker Community Forums

Share and learn in the Docker community.

How to ignore uploads folder and its content to be removed on docker server when new build is created

dockerhub
docker

(Irshaddocker) #1

Hello All,

I have created one “uploads” folder on server and i am uploading image in this folder using upload functionality of PHP, now whenever a new build is created my newly created folder and uploaded files are removed which are inside this folder, as docker looks the repo for creating new image and not considering newly uploaded folder and files. So, can anyone let me know what is the technique of “uploading image” functionality using PHP on docker.

Shall i create dockerignore file for informing docker to not to touch my “uploads” folder ? Will this work? I doubt that dockeringore file will surely ignore “uploads” folder but the new image may not have my newly created folder and files inside the “uploads” folder as “uploads” folder is present in repo but my newly created folder and files are not present in repo so while creating new image docker may pick the “uploads” folder from repo and will ignore it also but will not include the newly created folder and files inside this folder. But this is my assumption.

Any help will be appreciable.

Thanks in advance.

Thanks
Irshad


(Allan Sun) #2

A .dockerignore file will be able to ignore any contents you specified.

Unlike .gitignore you might have used, the docker image is built in ‘layers’, and it won’t track histories in layer (each RUN/ADD and other docker file commands used is causing a new layer). So if you put ‘uploads’ folder into your .dockerignore file, anythings in that folder will be gone in your new docker image.

A proper solution for storing ‘uploads’ file is to use online storage service like AWS S3, or if you like you can use ‘volumes’ to mount external directory on your host (though I don’t consider this as a proper way to use in production environment).


(Irshaddocker) #3

Thanks for the reply,

Do you think that the uploads folder and its content will be preserved in the next build also if i use .dockerignorefile ?