DEV Community

Cover image for #018 .dockerignore
Omar
Omar

Posted on

#018 .dockerignore

Introduction

this is part 18 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


Docker ignore

if you use git before (if not I will cover it somewhere in the journey) there is .gitignore file where when you push your files to github he will ignore to push files listed in .gitignore same here for docker.

what we should ignore ? maybe some environments files , cached files , node_modules folder .
and for security reasons , let's say you need to safe some api_key locally or login credentials.

meme


Download app_018

app_015

if you follow part 9

cd location/DevOpsJourney/
git pull
cd app_018/
Enter fullscreen mode Exit fullscreen mode

replace location with where you put the DevOpsJourney

if your new go to part 9 and do same steps will download old lecture files and new one.


lab

adding a file

if you clone the repo and go to app_018 you should see our login file already there.

let's create our .dockerignore file
i use vim to it , inside folder app_018

vim .dockerignore
Enter fullscreen mode Exit fullscreen mode

ignore

as you see i put .dockerignore and logindata.txt
so when we are going to build he will not copy those to our image that we will build so it's stay locally.
some patterns you may find help full

.git
*.json
location/*.txt
Enter fullscreen mode Exit fullscreen mode

if your project will be uploaded to git you should ignore the .git folder , usually you not gonna see it because every folder start with . will be hidden in linux you can run

ls -a
Enter fullscreen mode Exit fullscreen mode

to see all the files in directory.

*.json , * mean all so here I am telling him ignore all json files

location/*.txt mean ignore all the txt files inside a folder (location is folder name)


build and see

build

docker image build -t app_018 .
Enter fullscreen mode Exit fullscreen mode

always when you follow me watch out for where i am running my commands , here I am inside ~/Documents/DevOpsJourney/app_018 so to build I need to use . (mean Dockerfile is here in this folder)

proof

docker run --rm --name app_018 -exec -it app_018 sh
ls
Enter fullscreen mode Exit fullscreen mode

as we can see the image does not have the logindata.txt inside , cool!
as challange try to not copy Dockerfile also

Top comments (0)