I have to build a simple app which reads a text file and process it’s content (like remove multiple spaces, process words etc) but my I am confused about the first part of my homework.
"Initialize a git repository in a docker container then implement an app…."
I use Debian, I installed docker and git and I studied about it. From what I read I have to create a Dockerfile which will contain some instructions then I build the image and then run the container, run?
But I am still confused, what is the order of these thigs? Can I go firstly and write the app in Intelij and then to create that Dockerfiler? Or I have to create first the container then to code the app? But how I build the container? I read a lot about this, can you give me some advice? I mention that after every app "task" (read text file, process text etc) I have to execute git add, git commit and git push (if it helps for answer)
2
Answers
If the instruction says to "Initialize a Git repository in a docker container" then you are expected to:
You could:
This will run a Debian "buster" image as a container and should (!) give you a shell prompt in the container.
A directory
/homework
in the container will be mapped to your host machine’s${PWD}/homework
and you will be in the/homework
directory when the container starts. This means that you won’t lose your work if you exit the container.From within the container’s prompt:
Notes
docker run ...
command to return to it.ls -la ${PWD}/homework
to see the.git
directory (at least) persisted on your host.${PWD}/homework
. Or revise the--volume=...
I’d recommend an overall workflow of
You should be able to build the application totally normally. Whatever language you’re using to build the application, make sure to use its normal packaging tools. For example, your
package.json
/Gemfile
/requirements.txt
/go.mod
should list out all of the library dependencies your application needs to run. Run it locally, write appropriate unit tests for it, and generally build something that works.Once it works, then push it into Docker. You’ll need to write a Dockerfile that builds the image. A generic recipe for this is
You should then be able to
docker build
an image, anddocker run
a container from the resulting image. The Docker documentation includes a sample application that runs through this sequence.Note in particular that the problem task of "read a text file" is substantially harder in Docker than without. You need to use a bind mount to give access to the host filesystem to the container, and then refer to the container-side path. For example,
I would not bother trying to use Docker as my primary development environment, especially for an introductory project. Docker is designed as an isolation system and it’s intentionally tricky to work with host files from a container, and vice versa. Especially if you can use a fairly routine programming language that you can easily install with
apt-get
orbrew
, and you don’t have tricky host-library dependencies, it’s substantially easier to do most of your development in an ordinary host build environment use Docker only at a late stage.