Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy a file to a Docker container before starting/running it?

Tags:

docker

I'm starting with a docker image that is already built. I would like to do this

  1. Create a docker container from this image. (Don't start)
  2. Copy a file to this container
  3. Start the container

How can this be achieved. It looks like if i run the following commands the file doesn't end up in the container

  1. docker create --name my_container my_image
  2. docker cp file my_container:/tmp/file
  3. docker start my_container

Any idea how this can be achieved ?

like image 468
Abhijith Avatar asked Feb 15 '16 20:02

Abhijith


1 Answers

You will have to create a new image from a Dockerfile that inherit from the one that is already built, and the use the COPY tag:

Dockerfile

FROM my_image
COPY file /tmp/file

Finally, build that new Dockerfile:

$ docker build -t new_image .
like image 135
JesusTinoco Avatar answered Oct 04 '22 21:10

JesusTinoco