Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

docker - Dockerignore: Ignore everything except a file and the Dockerfile

So the main intention was to dockerize a fat jar application and put it into Elasticbeanstalk. The problem is with the context. It's a little bit stupid to add so much context into docker if all I need is actually a single jar file.

I've been playing around with the .dockerignore file, but I am lost. I tried to use the gitignore negation, but it doesn't work.

*
!Dockerfile
*/
!target/
target/*
!target/*.jar

There's also that thing with regex, but it seems like complicated regex is not supported.

^((?!Dockerfile).)*$

I have also tried searching in stackoverflow, and these two are all I found:

This question might be similiar to the second one, but I think it's slightly difference since in here, I just want to include a single file into the context.

Any help will be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you need to ignore everything except some directories or files and also ignore some unnecessary files inside those allowed directories you can use the following .dockerignore file:

# Ignore everything
**

# Allow files and directories
!/file.txt
!/src/**

# Ignore unnecessary files inside allowed directories
# This should go after the allowed directories
**/*~
**/*.log
**/.DS_Store
**/Thumbs.db

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...