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?
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.
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.
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
There is a statement in .dockerignore file documentation:
Note: For historical reasons, the pattern . is ignored.
                        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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With