.dockerignore mentioned files are not ignored - docker

I'm having in Dockerfile:
ENV DATARATOR_HOME /usr/local/share/datarator
RUN mkdir -p $DATARATOR_HOME
COPY . $DATARATOR_HOME
and .dockerignore file:
/Gemfile.lock
/coverage
/spec
*.bundle
*.so
*.o
*.a
mkmf.log
*.swp
/.*
/tmp
/log
However, once showing files in the built container, I can see also those that are supposed to be ignored:
/usr/local/share/datarator # ls -lha
total 128
drwxr-xr-x 10 root root 4.0K Mar 29 21:01 .
drwxr-xr-x 4 root root 4.0K Mar 29 21:00 ..
drwxr-xr-x 2 root root 4.0K Mar 29 21:01 .bundle
-rw-rw-r-- 1 root root 24 Mar 29 20:37 .coveralls.yml
-rw-rw-r-- 1 root root 81 Mar 29 20:37 .dockerignore
drwxrwxr-x 8 root root 4.0K Mar 29 20:37 .git
-rw-rw-r-- 1 root root 85 Mar 29 20:37 .gitignore
-rw-rw-r-- 1 root root 1.2K Mar 29 20:37 .travis.yml
-rw-rw-r-- 1 root root 509 Mar 29 20:37 .vimrc
-rw-rw-r-- 1 root root 959 Mar 29 20:37 Dockerfile
-rw-rw-r-- 1 root root 94 Mar 29 20:37 Gemfile
-rw-r--r-- 1 root root 2.7K Mar 29 21:01 Gemfile.lock
-rw-rw-r-- 1 root root 343 Mar 29 20:37 Guardfile
-rw-rw-r-- 1 root root 1.0K Mar 29 20:37 LICENSE.txt
-rw-rw-r-- 1 root root 71 Mar 29 20:37 Procfile
-rw-rw-r-- 1 root root 14.8K Mar 29 20:37 README.md
-rw-rw-r-- 1 root root 198 Mar 29 20:37 Rakefile
drwxrwxr-x 2 root root 4.0K Mar 29 20:37 bin
drwxrwxr-x 2 root root 4.0K Mar 29 20:37 config
-rw-rw-r-- 1 root root 97 Mar 29 20:37 config.ru
-rw-r--r-- 1 root root 16.0K Mar 29 21:01 datarator-0.0.1.gem
-rw-rw-r-- 1 root root 1.7K Mar 29 20:37 datarator.gemspec
drwxrwxr-x 4 root root 4.0K Mar 29 20:37 lib
drwxrwxr-x 2 root root 4.0K Mar 29 20:37 log
drwxrwxr-x 3 root root 4.0K Mar 29 20:37 spec
drwxrwxr-x 2 root root 4.0K Mar 29 20:37 tmp
How can I achieve having all those mentioned in the .dockerignore file ignored?

The .dockerignore rules follow the filepath/#Match.
Try (for testing) Gemfile.lock instead of /Gemfile.lock.
And check that the eol (end of line) characters are unix-style, not Windows style in your .dockerignore file.
Apparently, (docker 1.10, March 2016) using rule starting with / like /xxx ( or /.*) is not well supported.

Here's the complete syntax for the .dockerignore:
pattern:
{ term }
term:
'*' matches any sequence of non-Separator characters
'?' matches any single non-Separator character
'[' [ '^' ] { character-range } ']'
character class (must be non-empty)
c matches character c (c != '*', '?', '\\', '[')
'\\' c matches character c
character-range:
c matches character c (c != '\\', '-', ']')
'\\' c matches character c
lo '-' hi matches character c for lo <= c <= hi
additions:
'**' matches any number of directories (including zero)
'!' lines starting with ! (exclamation mark) can be used to make exceptions to exclusions
'#' lines starting with this character are ignored: use it for comments
Therefore, some of your matches would be changed according to the above syntax:
/Gemfile.lock --> */Gemfile.lock or **/Gemfile.lock or *.lock
/spec --> */spec or **/spec
/tmp --> in the same way
/log --> in the same way
Here are two articles to explain more:
Reference
Reference

Related

How do I fix ln -s not working in Docker?

Step 3/10 : RUN mkdir -p /etc/nginx/{sites-available,sites-enabled}
Step 4/10 : COPY nginx.conf /etc/nginx/
Step 5/10 : COPY sites-available/*.conf /etc/nginx/sites-available/
Step 6/10 : RUN ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/
---> Running in a2f39a3fd6b3
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
ln: /etc/nginx/sites-enabled/: No such file or directory
The command '/bin/sh -c ln -s /etc/nginx/sites-available/* /etc/nginx/sites-enabled/*' returned a non-zero code: 1
Any clue why this isn't working? ^^
I tried all these commands outside of a docker container and it seemed to work
This could be solved by copying the files directly to the sites-enabled directory with the following statement:
COPY sites-available/*.conf /etc/nginx/sites-enabled/
Your step 3 includes a bashism:
mkdir -p /etc/nginx/{sites-available,sites-enabled}
With the default /bin/sh, this will create a single directory rather than the two directories you wanted:
$ docker run -it --rm nginx /bin/sh
# ls -al /etc/nginx
total 48
drwxr-xr-x 3 root root 4096 Dec 28 15:20 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
# mkdir -p /etc/nginx/{sites-available,sites-enabled}
# ls -al /etc/nginx
total 56
drwxr-xr-x 1 root root 4096 Jan 26 19:47 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
drwxr-xr-x 2 root root 4096 Jan 26 19:47 {sites-available,sites-enabled}
For /bin/sh, you need to list them individually:
# mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
# ls -al /etc/nginx
total 64
drwxr-xr-x 1 root root 4096 Jan 26 19:49 .
drwxr-xr-x 1 root root 4096 Jan 26 19:46 ..
drwxr-xr-x 2 root root 4096 Dec 28 15:20 conf.d
-rw-r--r-- 1 root root 1007 Nov 19 12:50 fastcgi_params
-rw-r--r-- 1 root root 2837 Nov 19 12:50 koi-utf
-rw-r--r-- 1 root root 2223 Nov 19 12:50 koi-win
-rw-r--r-- 1 root root 5231 Nov 19 12:50 mime.types
lrwxrwxrwx 1 root root 22 Nov 19 12:50 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 643 Nov 19 12:50 nginx.conf
-rw-r--r-- 1 root root 636 Nov 19 12:50 scgi_params
drwxr-xr-x 2 root root 4096 Jan 26 19:49 sites-available
drwxr-xr-x 2 root root 4096 Jan 26 19:49 sites-enabled
-rw-r--r-- 1 root root 664 Nov 19 12:50 uwsgi_params
-rw-r--r-- 1 root root 3610 Nov 19 12:50 win-utf
drwxr-xr-x 2 root root 4096 Jan 26 19:47 {sites-available,sites-enabled}

Microsoft.AspNetCore.App 2.2.7 not found in Docker image built from project using Paket

I have a docker image built from an F# project that uses Paket. At run time the image fails with:
It was not possible to find any compatible framework version The
specified framework 'Microsoft.AspNetCore.App', version '2.2.7' was
not found.
My dockerfile looks like this:
# Two stage build because Paket means project files reference external files
# via <Import Project="..\.paket\Paket.Restore.targets" />
# https://github.com/fsprojects/Paket/issues/3006#issuecomment-359750323
FROM microsoft/dotnet:2.2-sdk-alpine AS build
RUN apk update \
&& apk add --no-cache bash
WORKDIR /app
# copy fsproj and restore as distinct layers
COPY MyCompany.WebApi/MyCompany.WebApi.fsproj ./MyCompany.WebApi/
COPY NuGet.config ./
RUN dotnet restore MyCompany.WebApi/MyCompany.WebApi.fsproj --configfile NuGet.config
# copy everything else and build
COPY . ./
RUN dotnet publish MyCompany.WebApi/MyCompany.WebApi.fsproj -c Release -o out
# build runtime image
FROM microsoft/dotnet:2.2-sdk-alpine AS final
RUN apk update \
&& apk add --no-cache bash
WORKDIR /app
COPY --from=build /app/MyCompany.WebApi/out ./
ENTRYPOINT ["dotnet", "MyCompany.WebApi.dll"]
Same problem occurs if I use 2.2-runtime-alpine as the basis for final.
My packet.lock includes these lines:
// https://github.com/fsharp/FAKE/issues/2193:
version 5.216.0
...
source https://api.nuget.org/v3/index.json
...
nuget Microsoft.AspNetCore.App
...
I notice that my generated paket.dependencies specifies a particular version of Microsoft.AspNetCore.App:
Microsoft.AspNetCore.App (2.2.7)
Microsoft.AspNet.WebApi.Client (>= 5.2.6 < 5.3) - restriction: >= netcoreapp2.2
Microsoft.AspNetCore (>= 2.2 < 2.3) - restriction: >= netcoreapp2.2
Microsoft.AspNetCore.Antiforgery (>= 2.2 < 2.3) - restriction: >= netcoreapp2.2
...although it looks like we are discouraged from specifying versions:
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2
So my question is: is it possible to come up with a combination of Docker, Paket, F# and AspNetCore that works together?
Edit: paket.dependencies -> packet.lock
Edit 2: Here's a listing of the entry point's directory and below:
.:
total 18668
-rwxr--r-- 1 root root 190976 Aug 29 13:18 Dapper.dll
-rwxr--r-- 1 root root 2850168 Aug 2 19:03 FSharp.Core.dll
-rwxr--r-- 1 root root 243200 Apr 16 08:00 Fable.Core.dll
-rwxr--r-- 1 root root 342528 Feb 10 2019 Giraffe.dll
...lots more DLLs from Nuget dependencies
... some DLLs from our internal dependencies
-rw-r--r-- 1 root root 100670 Sep 12 13:23 MyCompany.WebApi.deps.json
-rwxr-xr-x 1 root root 61440 Sep 12 13:23 MyCompany.WebApi.dll
-rw-r--r-- 1 root root 10608 Sep 12 13:23 MyCompany.WebApi.pdb
-rw-r--r-- 1 root root 149 Sep 12 13:23 MyCompany.WebApi.runtimeconfig.json
-rwxr--r-- 1 root root 178824 Nov 28 2018 System.Net.Http.Formatting.dll
-rwxr--r-- 1 root root 23088 Sep 18 2018 System.Runtime.CompilerServices.Unsafe.dll
-rwxr--r-- 1 root root 29744 Feb 15 2019 System.Security.Cryptography.OpenSsl.dll
-rwxr--r-- 1 root root 189168 Nov 29 2018 System.Security.Cryptography.Pkcs.dll
-rwxr--r-- 1 root root 29760 Jul 19 2018 System.ServiceModel.Primitives.dll
-rwxr--r-- 1 root root 30784 Jul 19 2018 System.ServiceModel.dll
-rwxr--r-- 1 root root 759024 Nov 29 2018 System.Text.Encoding.CodePages.dll
-rwxr--r-- 1 root root 91136 Sep 16 2018 TaskBuilder.fs.dll
drwxr-xr-x 2 root root 4096 Sep 12 13:23 cs
drwxr-xr-x 2 root root 4096 Sep 12 13:23 de
drwxr-xr-x 2 root root 4096 Sep 12 13:23 es
drwxr-xr-x 2 root root 4096 Sep 12 13:23 fr
drwxr-xr-x 2 root root 4096 Sep 12 13:23 it
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ja
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ko
drwxr-xr-x 2 root root 4096 Sep 12 13:23 pl
-rwxr--r-- 1 root root 277504 Aug 30 2018 protobuf-net.dll
drwxr-xr-x 2 root root 4096 Sep 12 13:23 pt-BR
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ru
drwxr-xr-x 4 root root 4096 Sep 12 13:23 runtimes
drwxr-xr-x 2 root root 4096 Sep 12 13:23 tr
drwxr-xr-x 2 root root 4096 Sep 12 13:23 zh-Hans
drwxr-xr-x 2 root root 4096 Sep 12 13:23 zh-Hant
./cs:
total 376
-rwxr--r-- 1 root root 33144 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 308088 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 34896 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./de:
total 392
-rwxr--r-- 1 root root 34168 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 327544 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./es:
total 388
-rwxr--r-- 1 root root 33360 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 321104 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35920 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./fr:
total 392
-rwxr--r-- 1 root root 33656 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 327544 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36432 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./it:
total 392
-rwxr--r-- 1 root root 33144 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 325496 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./ja:
total 428
-rwxr--r-- 1 root root 35704 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 358776 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 38264 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./ko:
total 396
-rwxr--r-- 1 root root 34680 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 331336 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36728 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./pl:
total 396
-rwxr--r-- 1 root root 34168 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 331128 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./pt-BR:
total 380
-rwxr--r-- 1 root root 32632 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 316280 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35704 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./ru:
total 508
-rwxr--r-- 1 root root 39800 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 430968 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 42360 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./runtimes:
total 8
drwxr-xr-x 3 root root 4096 Sep 12 13:23 unix
drwxr-xr-x 3 root root 4096 Sep 12 13:23 win
./runtimes/unix:
total 4
drwxr-xr-x 4 root root 4096 Sep 12 13:23 lib
./runtimes/unix/lib:
total 8
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.1
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netstandard2.0
./runtimes/unix/lib/netcoreapp2.1:
total 88
-rwxr--r-- 1 root root 86280 Feb 15 2019 System.Security.Cryptography.OpenSsl.dll
./runtimes/unix/lib/netstandard2.0:
total 1848
-rwxr--r-- 1 root root 1889344 Jul 19 2018 System.Private.ServiceModel.dll
./runtimes/win:
total 4
drwxr-xr-x 5 root root 4096 Sep 12 13:23 lib
./runtimes/win/lib:
total 12
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.0
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.1
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netstandard2.0
./runtimes/win/lib/netcoreapp2.0:
total 744
-rwxr--r-- 1 root root 761392 Nov 29 2018 System.Text.Encoding.CodePages.dll
./runtimes/win/lib/netcoreapp2.1:
total 212
-rwxr--r-- 1 root root 214064 Nov 29 2018 System.Security.Cryptography.Pkcs.dll
./runtimes/win/lib/netstandard2.0:
total 1848
-rwxr--r-- 1 root root 1889344 Jul 19 2018 System.Private.ServiceModel.dll
./tr:
total 376
-rwxr--r-- 1 root root 32632 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 312184 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35192 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./zh-Hans:
total 344
-rwxr--r-- 1 root root 31096 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 278904 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 33144 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
./zh-Hant:
total 344
-rwxr--r-- 1 root root 30584 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 280144 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 33360 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll
I think I've fixed this. Changed the base image to one I found referenced in a Microsoft tutorial, and removed the apk update stage (as this returned a non-zero exit code with this new base image). So this is my dockerfile now.
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app
# copy fsproj and restore as distinct layers
COPY MyCompany.WebApi/MyCompany.WebApi.fsproj ./MyCompany.WebApi/
COPY NuGet.config ./
RUN dotnet restore MyCompany.WebApi/MyCompany.WebApi.fsproj --configfile NuGet.config
# copy everything else and build
COPY . ./
RUN dotnet publish MyCompany.WebApi/MyCompany.WebApi.fsproj -c Release -o out
# build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS final
WORKDIR /app
COPY --from=build /app/MyCompany.WebApi/out ./
ENTRYPOINT ["dotnet", "MyCompany.WebApi.dll"]
It starts up OK now, haven't yet tested the functionality!
I am far from a Docker or Linux expert, but I would hazard a guess that the Alpine image hasn't caught up with the latest dotnet releases. I would also guess that the image I create after this change is fatter than it needs to be, but I'll take 'fat and working' for now.

docker cp - "Error response from daemon: not a directory"

I am trying to copy file from docker to host using the below command,
docker cp <container_name>:<file FQN> ./
But getting the below error,
Error response from daemon: not a directory
As verified, the file name and container name are valid.
Note: Using Docker in Mac
Thanks for all the answers. After a bit of struggle found out that the error message was not actually directly related to the docker cp command.
The scenario was, I ran the docker with the link to a local file. When the docker was running I deleted it. Then the file got created as a folder somehow (Probably, when I restarted the docker).
And whenever I am executing some command, the docker was giving me that error. Then once I created the file the error disappeared.
It seems your command is correct. You please try like the below from your local machine not from inside the container. sometimes unfortunately if we run this command with in the container we will get this kind of errors.
docker cp [container_name]:[docker dir abs path] [host dir path]
Hope it will help you.
Here is a full example on how to copy a file:
$ docker run -it ubuntu /bin/bash
root#9fc8a1af7f23:/#
root#9fc8a1af7f23:/# ll
total 72
drwxr-xr-x 34 root root 4096 Jul 13 21:51 ./
drwxr-xr-x 34 root root 4096 Jul 13 21:51 ../
-rwxr-xr-x 1 root root 0 Jul 13 21:51 .dockerenv*
drwxr-xr-x 2 root root 4096 Feb 14 23:29 bin/
drwxr-xr-x 2 root root 4096 Apr 12 2016 boot/
drwxr-xr-x 5 root root 360 Jul 13 21:51 dev/
drwxr-xr-x 45 root root 4096 Jul 13 21:51 etc/
drwxr-xr-x 2 root root 4096 Apr 12 2016 home/
drwxr-xr-x 8 root root 4096 Sep 13 2015 lib/
drwxr-xr-x 2 root root 4096 Feb 14 23:29 lib64/
drwxr-xr-x 2 root root 4096 Feb 14 23:28 media/
drwxr-xr-x 2 root root 4096 Feb 14 23:28 mnt/
drwxr-xr-x 2 root root 4096 Feb 14 23:28 opt/
dr-xr-xr-x 288 root root 0 Jul 13 21:51 proc/
drwx------ 2 root root 4096 Feb 14 23:29 root/
drwxr-xr-x 6 root root 4096 Feb 27 19:41 run/
drwxr-xr-x 2 root root 4096 Feb 27 19:41 sbin/
drwxr-xr-x 2 root root 4096 Feb 14 23:28 srv/
dr-xr-xr-x 13 root root 0 Jul 13 21:51 sys/
drwxrwxrwt 2 root root 4096 Feb 14 23:29 tmp/
drwxr-xr-x 11 root root 4096 Feb 27 19:41 usr/
drwxr-xr-x 13 root root 4096 Feb 27 19:41 var/
root#9fc8a1af7f23:/# cd tmp/
root#9fc8a1af7f23:/tmp# ls
root#9fc8a1af7f23:/tmp# echo "hello docker" > docker_test.txt
root#9fc8a1af7f23:/tmp# cat docker_test.txt
hello docker
root#9fc8a1af7f23:/tmp#
Then, in another terminal
dali#dali-X550JK:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fc8a1af7f23 ubuntu "/bin/bash" 2 minutes ago Up 2 minutes fervent_hodgkin
dali#dali-X550JK:~$ docker cp fervent_hodgkin:/tmp/docker_test.txt /tmp/
dali#dali-X550JK:~$ cat /tmp/docker_test.txt
hello docker
dali#dali-X550JK:~$
Please follow these instruction, make sure your don't have typo in the file paths, otherwise share a reproducible error.
This error also appears when trying to copy a file that is actually a volume in the container, but the file has been deleted on the host.
This is simply an error in the path you want to copy.
You may not believe it, but that it is.

Ignoring subfolders not working

I'm using a .dockerignore file that looks like this:
*
*/node_modules
*/bower_components
!www
!app
!inc
so here what I'm saying is: ignore all files in the current directory (this post is related to: How to include local libraries in build?) except for www, app and inc and ignore all directories named node_modules and bower_components in those subdirectories
when I run a build:
build --no-cache -t test -f app/Dockerfile .
(here's my Dockerfile):
FROM node:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD . /usr/src/app/
and then run a container:
run -i --entrypoint=/bin/bash test
if I look in the directory I see node_modules folders!
# ls -alF
total 20
drwxr-xr-x 5 root root 4096 Mar 19 03:39 ./
drwxr-xr-x 4 root root 4096 Mar 19 03:39 ../
drwxr-xr-x 4 root root 4096 Mar 18 03:26 inc/
drwxr-xr-x 3 root root 4096 Mar 19 00:57 app/
drwxr-xr-x 12 root root 4096 Mar 18 08:55 www/
# ls -alF app
total 36
drwxr-xr-x 3 root root 4096 Mar 19 00:57 ./
drwxr-xr-x 5 root root 4096 Mar 19 03:39 ../
-rw-r--r-- 1 root root 38 Mar 19 00:57 .dockerignore
-rw-r--r-- 1 root root 359 Mar 19 03:37 Dockerfile
-rw-r--r-- 1 root root 700 Mar 18 04:50 config.json
-rw-r--r-- 1 root root 3786 Mar 18 03:43 index.js
drwxr-xr-x 119 root root 4096 Mar 17 18:57 node_modules/
-rw-r--r-- 1 root root 2910 Mar 17 20:51 npm-debug.log
-rw-r--r-- 1 root root 348 Mar 19 03:24 package.json
so the first line of the .dockerignore worked fine, as did the 4th, 5th and 6th lines, but the subdirectories failed. for the sake of completeness I originally used **/node_modules but that failed too.
what is the correct way of expressing this?
ok, apparently the problem is that when I create exceptions to the ignore rules, I have to reapply the exceptions, so if I do this instead:
*
!www
!app
!inc
*/node_modules
*/bower_components
it works because */node_modules applies to "all of the above", which includes app. in my original declaration I was excluding the directories I do want to include from the rules

Issue with docker-py in executing /bin/bash

I have a docker image built from ubuntu base image with few softwares installed.
i have a startup script, as below
#!/bin/bash
/usr/local/sbin/process1 -d
/usr/local/sbin/process2 -d
/bin/bash
Now I use docker-py python library to start multiple of these containers from a python file.
c = docker.Client(base_url='unix://var/run/docker.sock',
version='1.12',
timeout=10)
container = c.create_container("p12", command="/startup.sh", hostname=None, user=None,
detach=False, stdin_open=False, tty=False, mem_limit=0,
ports=None, environment=None, dns=None, volumes=None,
volumes_from=None, network_disabled=False, name=None,
entrypoint=None, cpu_shares=None, working_dir=None,
memswap_limit=0)
c.start(container, binds=None, port_bindings=None, lxc_conf=None,
publish_all_ports=False, links=None, privileged=False,
dns=None, dns_search=None, volumes_from=None, network_mode=None,
restart_policy=None, cap_add=None, cap_drop=None)
This worked fine and I can start multiple (say 3) when I tested this on a Ubuntu Desktop, Ubuntu 14.04.1 LTS and with docker-py version of 1.10. It will start the dockers and I can do a docker attach later and work on the terminal.
Now i moved my testing environment to a Ubuntu Server edition with Ubuntu 14.04.1 LTS and with docker-py version of 1.12.
The issue i see is that, when I use the same script and try to start 3 dockers, after starting process1 and process 2 as background processes, all the dockers simply exit. It appears as if /bin/bash doesnt execute at all.
If i execute the same docker image as "docker run -t -i p14 /startup.sh --> then everything is fine again. The docker is started appropriately and i get the terminal access.
The only issue is when i execute this python library.
anybody has any similar issues...any idea on how to debug this problem...or any pointers for the fix ?
Thanks,
Kiran
The difference is you're in tty (-t) mode with an open stdin (-i) when you run your docker image with docker run -t -i p14 /startup.sh, whereas you set both stdin_open=False and tty=False in your docker-py configuration.
Because your docker container has no tty and can't take any input from stdin, your call to /bin/bash has nothing to do so exits with code 0.
Try it yourself:
An open stdin with a tty
$ docker run -t -i ubuntu:14.04 /bin/bash
root#1e7eda2bba03:/# ls -la
total 7184
drwxr-xr-x 21 root root 4096 Sep 19 21:30 .
drwxr-xr-x 21 root root 4096 Sep 19 21:30 ..
-rwxr-xr-x 1 root root 0 Sep 19 21:30 .dockerenv
-rwx------ 1 root root 7279686 Jul 21 10:50 .dockerinit
drwxr-xr-x 2 root root 4096 Sep 3 03:33 bin
drwxr-xr-x 2 root root 4096 Apr 10 22:12 boot
drwxr-xr-x 4 root root 360 Sep 19 21:30 dev
drwxr-xr-x 61 root root 4096 Sep 19 21:30 etc
drwxr-xr-x 2 root root 4096 Apr 10 22:12 home
drwxr-xr-x 12 root root 4096 Sep 3 03:33 lib
drwxr-xr-x 2 root root 4096 Sep 3 03:33 lib64
drwxr-xr-x 2 root root 4096 Sep 3 03:33 media
drwxr-xr-x 2 root root 4096 Apr 10 22:12 mnt
drwxr-xr-x 2 root root 4096 Sep 3 03:33 opt
dr-xr-xr-x 240 root root 0 Sep 19 21:30 proc
drwx------ 2 root root 4096 Sep 3 03:33 root
drwxr-xr-x 7 root root 4096 Sep 3 03:33 run
drwxr-xr-x 2 root root 4096 Sep 4 18:41 sbin
drwxr-xr-x 2 root root 4096 Sep 3 03:33 srv
dr-xr-xr-x 13 root root 0 Sep 19 18:44 sys
drwxrwxrwt 2 root root 4096 Sep 4 18:41 tmp
drwxr-xr-x 10 root root 4096 Sep 3 03:33 usr
drwxr-xr-x 11 root root 4096 Sep 3 03:33 var
root#1e7eda2bba03:/#
An open stdin with no tty (i.e., no prompt, but you can still send commands via stdin)
$ docker run -i ubuntu:14.04 /bin/bash
ls -la
total 7184
drwxr-xr-x 21 root root 4096 Sep 19 21:32 .
drwxr-xr-x 21 root root 4096 Sep 19 21:32 ..
-rwxr-xr-x 1 root root 0 Sep 19 21:32 .dockerenv
-rwx------ 1 root root 7279686 Jul 21 10:50 .dockerinit
drwxr-xr-x 2 root root 4096 Sep 3 03:33 bin
drwxr-xr-x 2 root root 4096 Apr 10 22:12 boot
drwxr-xr-x 4 root root 340 Sep 19 21:32 dev
drwxr-xr-x 61 root root 4096 Sep 19 21:32 etc
drwxr-xr-x 2 root root 4096 Apr 10 22:12 home
drwxr-xr-x 12 root root 4096 Sep 3 03:33 lib
drwxr-xr-x 2 root root 4096 Sep 3 03:33 lib64
drwxr-xr-x 2 root root 4096 Sep 3 03:33 media
drwxr-xr-x 2 root root 4096 Apr 10 22:12 mnt
drwxr-xr-x 2 root root 4096 Sep 3 03:33 opt
dr-xr-xr-x 243 root root 0 Sep 19 21:32 proc
drwx------ 2 root root 4096 Sep 3 03:33 root
drwxr-xr-x 7 root root 4096 Sep 3 03:33 run
drwxr-xr-x 2 root root 4096 Sep 4 18:41 sbin
drwxr-xr-x 2 root root 4096 Sep 3 03:33 srv
dr-xr-xr-x 13 root root 0 Sep 19 18:44 sys
drwxrwxrwt 2 root root 4096 Sep 4 18:41 tmp
drwxr-xr-x 10 root root 4096 Sep 3 03:33 usr
drwxr-xr-x 11 root root 4096 Sep 3 03:33 var
A closed stdin with a tty (you can see the prompt but you can't enter any commands)
$ docker run -t ubuntu:14.04 /bin/bash
root#95904c21e5a5:/# ls -la
hello
this does nothing :(
A closed stdin with no tty - /bin/bash has nothing to do
$ docker run ubuntu:14.04 /bin/bash
$

Resources