Michael Durrant
Michael Durrant

Reputation: 96454

Docker - how to copy some files into my container without naming it?

This should be obvious but it isn't (i've gone through the docker site a dozen times)

I'm on Ubuntu.

I create a Dockerfile with

FROM ubuntu:18.04
COPY . /usr/src/app/
COPY docker_files/.bash_aliases /usr/src/app/

it seems to build ok

$ docker build .
Sending build context to Docker daemon  159.7kB
Step 1/3 : FROM ubuntu:18.04
 ---> 94e814e2efa8
Step 2/3 : COPY . /usr/src/app/
 ---> 2abbed3376c9
Step 3/3 : COPY docker_files/.bash_aliases /usr/src/app/
 ---> 42c7f78ad5ee
Successfully built 42c7f78ad5ee

The I run it

$ docker run -it ubuntu:18.04
root@366bd4a6ae0b:/# 

but where are my files? There is no app directory. Am i running the wrong image or what else did I get wrong ?

root@366bd4a6ae0b:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@366bd4a6ae0b:/# ls -a root
.  ..  .bashrc  .profile
root@366bd4a6ae0b:/# 

root@7d558e90f5b5:/# ls -a /usr/src/
.  ..
root@7d558e90f5b5:/# 

Update: if I name it it works (so yeah I wasn't actually using that image before):

$ docker build -t dock .                                                                                                                                                                               
Sending build context to Docker daemon  146.9kB                                                                                                                                                        
Step 1/3 : FROM ubuntu:18.04                                                                                                                                                                           
 ---> 94e814e2efa8                                                                                                                                                                                     
Step 2/3 : COPY . /usr/src/app/                                                                                                                                                                        
 ---> 231e0743a840                                                                                                                                                                                     
Step 3/3 : COPY docker_files/.bash_aliases /usr/src/app/                                                                                                                                               
 ---> 1fdd50a0d869                                                                                                                                                                                     
Successfully built 1fdd50a0d869                                                                                                                                                                        
Successfully tagged dock:latest                                                                                                                                                                        
16:34:12 durrantm u2018 /home/durrantm/Dropbox/_/ultimate-weather-org/ultimate-weather-ruby UL-38                                                                                                      
$ docker run -it dock                                                                                                                                                                                  
root@4aa8a80a45c7:/# ls -a /usr/src/app/                                                                                                                                                               
.  ..  .bash_aliases 

Is there a way to do it without the name?

Upvotes: 0

Views: 89

Answers (1)

Alfredo
Alfredo

Reputation: 159

As said in the previous comment, you are not running the image that you built.

You can try adding a custom name to your image when you build it:

Like:

docker build -t custom/myubuntu .

Then you can run it with:

docker run -it custom/myubuntu

And your files will be under:

/usr/src/app/

Upvotes: 1

Related Questions