Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hidden file .env not copied using Docker COPY

I have a Dockerfile and there is a syntax like this COPY ["Gemfile", "Gemfile.lock", "Procfile", ".env", "/huginn/"]

I use RUN /bin/bash -l -c "ls -a" to check file cope status, I find .env file doen't be copied to the image.

I change the .env file name to test.env and use COPY ["Gemfile", "Gemfile.lock", "Procfile", "test.env", "/huginn/"], then it work, test.env is copied to the image.

Anyone know why is? And any solution can let docker support COPY .env file name?

like image 543
Hsiu Chuan Tsao Avatar asked Feb 09 '17 09:02

Hsiu Chuan Tsao


People also ask

Does Docker build .ENV files?

If you are using docker-compose (which now comes bundled with Docker), . env is the default filename for the file that contains variables that are made available to the parser for the docker-compose. yml file ONLY, and not to the build process or container environment variables.

Does Docker copy overwrite existing file?

It seems that docker build won't overwrite a file it has previously copied. I have a dockerfile with several copy instructions, and files touched in earlier COPY directives don't get overwritten by later ones. After building this, $BASE/config/thatfile. yml contains the contents of file1.


3 Answers

If you have .dockerignore file then it might be you added to ignore hidden files like .git, .vagrant etc.

If .dockerfile ignoring hidden files then either you can enable to not ignore or change file name.

For more info about .dockerignore file

like image 62
pl_rock Avatar answered Oct 22 '22 20:10

pl_rock


There is a statement in .dockerignore file documentation:

Note: For historical reasons, the pattern . is ignored.
like image 20
Chetabahana Avatar answered Oct 22 '22 19:10

Chetabahana


share my dockerfile, it can work correctly now

FROM ruby:2.3

MAINTAINER Tomato <[email protected]>

ENV DEBIAN_FRONTEND noninteractive
ENV LANG C.UTF-8
ENV RAILS_VERSION 5.0.1

# install rails && bundler
RUN gem install rails --version "$RAILS_VERSION"

WORKDIR /huginn

# copy huginn config file
COPY ["Gemfile", "Gemfile.lock", "Procfile", ".env", "/huginn/"]
COPY lib/gemfile_helper.rb /huginn/lib/
COPY vendor/gems /huginn/vendor/gems

# run bundle install
RUN bundle install

# copy huginn
COPY . /huginn/
RUN ls -a

And there is a .dockerignore:

.git
tmp
log
doc
spec
media
.openshift
.bundle
vendor/bundle
db/*.sqlite3
public/system/*
coverage
.travis.yml
build_docker_image.sh
# Copied from .gitignore
*.rbc
*.sassc
.sass-cache
capybara-*.html
.rspec
!/tmp/.gitkeep
**.orig
rerun.txt
pickle-email-*.html
.idea/
.DS_Store
deployment/tmp
deployment/cookbooks
.vagrant
.*un~
.ruby-gemset
.ruby-version
manifest.yml
config/unicorn.rb
db/schema.rb
like image 1
Hsiu Chuan Tsao Avatar answered Oct 22 '22 19:10

Hsiu Chuan Tsao