Reputation: 20182
I've got a docker host. I've also got a container I created by running the run command..I didn't use a docker file yet, because I'm just not there yet, learning docker.
My question is if I'm planning on running an app in a container based off an ubuntu image, should I clone down my git file for that app from inside the container (when I'm bashed into it interactively) or should the container somehow read the files from the docker host and therefore clone my files down to a directory on the docker host instead? How are containers supposed to work with respect to running the app files and where those files should be cloned to?
Upvotes: 0
Views: 265
Reputation: 677
You can install the app from within the container or copy it (use COPY not ADD unless you have a good reason https://labs.ctl.io/dockerfile-add-vs-copy/) during the build process. They are both valid ways to do it.
The answer depends on what you are trying to achieve from that container. Is creating a new container something you'll do occasionally or frequently. Will you be sharing this image at some point of time with others? Dockerfiles are great for repeatable tasks. Each time you build it will create an image with the same consistent steps. I would recommend learning to write a Dockerfile as part of your leaning.
You could of course do the setup once manually inside the container then commit and push it. That way you (or someone else) can pull it again later and continue from that point. See https://docs.docker.com/engine/reference/commandline/commit/
Upvotes: 0
Reputation: 1915
I didn't use a docker file yet, because I'm just not there yet, learning docker.
This is a mistake. A docker container is not a VM. Actually creating an image and running containers from that image is what docker is about. The Dockerfile reference is a quite readable introduction with some excellent, simple, examples at the bottom.
That being said: If this is your code then it can live wherever you build your docker image from, then in the Dockerfile use ADD
to copy your code (or binaries) into the image (if you're developing your app and using the container for testing then using VOLUME
to mount the app in is common).
If this is "just some git repo" and you simply want to build it into the image you could use RUN git clone
in the Dockerfile the same way you'd use git clone
locally (assuming your image already has git
in it, and if it doesn't just use a RUN
command to install git
like you would normally--though you'll generally want to make sure to pass -y
or --noconfirm
or whatever the OS package manager takes for a
'don't ask me, just do it' flag).
A Dockerfile is just a list of steps to build an OS image: if you can do it in a VM running that OS you can do it with a RUN
in the Dockerfile: if the source is in git you can git clone
(and if it's source that needs to be compiled you could even run the compile right in your Dockerfile), or if it's distributed as a zip you could simply curl
and install.
I don't have an example of a Dockerfile doing a clone, but to show you some of what you can do in a Dockerfile here's one of mine which installs tar
with the OS package manager, then downloads and installs java
via curl
and the OS package manager, and then downloads and unpacks two tarred archives:
FROM centos:centos6
RUN set -x && \
yum install -y tar && \
yum clean all
RUN set -x && \
curl -sOL 'http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.rpm' \
-H 'Cookie: oraclelicense=accept-securebackup-cookie' && \
rpm -i jdk-7u51-linux-x64.rpm && \
rm jdk-7u51-linux-x64.rpm && \
echo 'export JAVA_HOME=/usr/java/jdk1.7.0_51/' >> ~/.bashrc
ENV HBASE_VERSION 0.94.24
RUN set -x && \
curl -L http://archive.apache.org/dist/hbase/hbase-$HBASE_VERSION/hbase-$HBASE_VERSION.tar.gz | \
tar zvx --null && \
echo "export HBASE_HOME=/hbase-$HBASE_VERSION" >> ~/.bashrc
ADD hbase-site.xml /hbase-$HBASE_VERSION/conf/hbase-site.xml
ADD run.sh /hbase-$HBASE_VERSION/bin/LOCAL-run.sh
ENV PHOENIX_VERSION 3.2.0
RUN set -x && \
curl -L http://archive.apache.org/dist/phoenix/phoenix-$PHOENIX_VERSION/bin/phoenix-$PHOENIX_VERSION-bin.tar.gz | \
tar zvx --null && \
cp /phoenix-$PHOENIX_VERSION-bin/common/phoenix-core-$PHOENIX_VERSION.jar /hbase-$HBASE_VERSION/lib/
CMD ["/hbase-0.94.24/bin/LOCAL-run.sh"]
Upvotes: 2
Reputation: 6293
You can run container by providing -v
option to run command as
$ docker run -v <path on host> : <path inside container> <image name>
This will mount the path inside the container to the path on the host.
Regarding app files to clone, exploring dockerfile is good one. The ADD
option will solve your issue.
Upvotes: 1