Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a file in a docker image

Tags:

docker

I've created a docker image of a project (very large project that takes time to compile) and I forgot to add a file in it.

I does not have to do with the build, it's just a test file.

Is it possible to add this file into my image without rebuilding everything ?

Thanks

like image 242
Ngahy Be Avatar asked Jun 19 '19 14:06

Ngahy Be


People also ask

Can you copy a file into a Docker image?

Dockerfiles are used to build Docker images, which are then instantiated into Docker containers. Dockerfiles can contain several different instructions, one of which is COPY. The COPY instruction lets us copy a file (or files) from the host system into the image.

Does Docker image contain files?

A Docker image contains application code, libraries, tools, dependencies and other files needed to make an application run.


2 Answers

Here's a full example to pull an image, add a local file to it, retag the image and push it back:

export IMAGE_URL=example.com/your_image:your_tag
docker pull $IMAGE_URL
docker create --name temp_container $IMAGE_URL
docker cp /host/path/to/file temp_container:/container/path/to/file
docker commit temp_container $IMAGE_URL
docker push $IMAGE_URL
like image 175
Tamlyn Avatar answered Oct 04 '22 02:10

Tamlyn


Yes its possible, do the steps:

  1. Mount the image and make a container
  2. Do the command:

    docker cp textFile.txt docker_container_name:/textFile.txt

  3. Commit the container to build a new image with new tag version or another name;

like image 27
Bruno Leyne Avatar answered Oct 04 '22 02:10

Bruno Leyne