Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When to pull from Docker repo and when from Git repo and then build?

Suppose I have a machine. It can be a single production server, one of production nodes in a cluster, some kind of staging server, a server or a cluster for testing or a developer workstation. Or something different.

Now I want to deliver app to the machine and run it. I can git pull && docker build. Or I can just docker pull. Or I can git pull to another machine and then scp code instead. Or I can scp docker image tar and then docker load instead of docker pull.

Sure, Git and Docker are completely different and often used both at the same time. However both have repositories and both can be used to store and deliver code. Even the commands themselves are called the same: push and pull. Docker even has image tags which resemble commits to some limited extend. Because tags also help keep several versions of the app.

There is even a tool for delivery of apps in Production completely based on Git. It's Capistrano. Capistrano git pulls the code to anther directory and then redirects a symlink to it in order to deploy.

The question is which reasons to consider when deciding whether to git pull or docker pull the code to deliver it to a machine?

like image 510
Gherman Avatar asked Mar 02 '18 14:03

Gherman


People also ask

When should I use Docker pull?

The 'docker pull' is a Docker command to download a Docker image or a repository locally on the host from a public or private registry. When we run any container and the specified Docker image is not present locally then it first pulls it from the registry.

What is difference between Docker and GitHub?

Docker belongs to "Virtual Machine Platforms & Containers" category of the tech stack, while GitHub can be primarily classified under "Code Collaboration & Version Control". Some of the features offered by Docker are: Integrated developer tools. open, portable images.

What happens when you do Docker pull?

Docker enables you to pull an image by its digest. When pulling an image by digest, you specify exactly which version of an image to pull. Doing so, allows you to “pin” an image to that version, and guarantee that the image you're using is always the same.


2 Answers

like the other answers say, git is for version control, e.g. for textfiles.

You build a docker container from a "dockerfile" (which is a textfile). This "dockerfile" is placed in a directory with many other files and folders.

So if you put this directory, where the dockerfile is located in, into a git repository, then everyone who has access to it, can build the same docker container, with the same configurations and everything.

is that what you mean?

So, the docker container is a "building" and the DOCKER-repository is a market where you can download already built buildings (images), from that you can run a virtualmachine/container.
And the files in the GIT-repository (this is like a big archive for e.g. documents) are the "construction plans". You "share" the different version of the "construction plans" via git, so everyone can build every version of the building.

Example Workflow:

In your development environment (your local computer):

  1. git pull - pull the "construction - instructions" from git repository (e.g. dockerfile)
  2. docker build - build the docker image from that dockerfile-instructions
  3. docker push myDockerRepo/myDockerImage:latest - push the newly built docker image into the DOCKER repository (NOT the git-repository)

In your production environment:

  1. docker pull myDockerRepo/myDockerImage:latest - pull the latest docker image from the DOCKER-repository
  2. docker run - run a new containerized instance (basically a VirtualMachine) FROM the docker image
like image 107
MacMartin Avatar answered Oct 18 '22 04:10

MacMartin


Docker and Git are 2 completely different technologies. Git is a Source Control solution, while in docker you can run apps in docker containers. Think of it a sort of 'new' virtualisation technology. You can use both at the same time hower, no problem.

.... EDIT ...

Docker doesn't keep a copy of your source code. With docker you can build an image based on your source code and put that in a repository. From that image you can run an app in a docker container. So as for workflow basically, you just develop using git, and for deployment you use Docker...

like image 17
Run CMD Avatar answered Oct 18 '22 04:10

Run CMD