Reputation: 370
I am creating a Docker image from a Dockerfile. It installs an application when pulled and the Dockerfile is the following:
#Base image
FROM centos:latest
#Update image
RUN yum install -y git \
&& yum install -y wget \
&& yum install -y make
RUN git clone https://github.com/lskatz/lyve-SET.git /lyve-SET-1.1.4f/ \
&& cd /lyve-SET-1.1.4f/ \
&& make install
I want to put files that I have locally into the container and I have found that I can do that by adding a line like COPY /home/username/lyve-SET-1.1.4f/ /lyve-SET-1.1.4f/
(for example) in the Dockerfile or by running the container, detaching then using docker cp
. However, I want to have the files in the docker image without requiring it to depend on my local directory. Basically, I want the users who pull the image to have the files in their container (when they run) without the image not being able to pull because it depends on copying files/folders from host to container. I was thinking of putting them on github and then having a RUN git clone
statement that takes the files from the remote repository.
Is there any other way to add these local files to the image? This project will also be a Continuous Integration/Continuous Development workflow and therefore there will constantly be files that I have to add to the image.
Upvotes: 5
Views: 10781
Reputation: 13804
#Base image
FROM centos:latest
#Update image
RUN yum install -y git # and so on
COPY /home/username/lyve-SET-1.1.4f/ /lyve-SET-1.1.4f/
ENTRYPOINT <entrypoint of your image>
CMD <arguments of your entrypoint>
Now, if you build this image, everything will be executed except ENTRYPOINT
and CMD
That means when you will build your image, your local data will be copied into your container. And it will be always in that image.
Now push this image into registry.
When user will pull this image, that image will contain data you have copied. No worries.
If you need to change your data, you need to build
again and push
.
Note: In this way, you need to
build
&push
every time you change code
Another option:
If you do not want to build
& push
every time you change code, you need to do copy-part in run-time.
Write a script that will clone git repository, when user will run docker.
Thar means, use this
COPY script.sh /script.sh
ENTRYPOINT ["./script.sh"]
In this script.sh
shell, do you git clone and other things you need to do.
In this way, when user will run your image, they will always get the latest code you have in git repository
Upvotes: 4