Docker build and push git code inside Azure devops - docker

I have a docker file which copies some code from git. When I put this docker file as part of Azure devops pipeline I am unable to get the code inside container. is git clone the only option or is there any way out of this?

The container is not having internet access to connect to the git repository. You can prebuild your image from local system and use the image from docker images registry.

Related

Push Docker image in Tar ball to a OpenShift Docker

I have a jenkins in a standalone Windows 7 server. We have a request to add a build job to build a project, which produce a Docker image in Tar ball format, and push the image into a remote Docker Registry, which resides in OpenShift.
Trying to find a jenkins plugin that can do this. Found that Docker Common plugin have some command but as i understood it can push the image only from a docker registry to another.
Any guide where i can push the tar ball to a remote registry through a standalone jenkins? Thank you.
may be this can be helpful, you can run docker on local windows server, and then load the image tar to local docker then push it to remote repo. Steps are given in this link.
https://docs.openshift.com/container-platform/3.11/install/disconnected_install.html#disconnected-populate-registry

Build a docker image on Gitlab CI/CD with alpine

I would like to build docker-image on Gitlab CI/CD with alpine. This docker has to download a website (only index.html) as a file with a date every 1 hour.
All dates/ files should be saved in the docker volume.
How to start with this? I am new in docker.
First you need to run a docker container using any image you want (alpine in your case).
Then set everything in it that you want to run (like download website)
Then create a docker image and host it on gitlab docker registry
Then you simply have to code .gitlab-ci.yaml file. After pushing that to your repository
Then you need to schedule your pipeline as mentioned here
https://docs.gitlab.com/ee/user/project/pipelines/schedules.html

how does gitlab ci clone repo into docker?

I'm familar with Bamboo but new to gitlab ci, I have tried several times with gitlab and found a key advantage of gitlab is the automatic cloning of git repository.
The tricky part is gitlab ci can even clone repository into docker container automatically.
my git repo:
.git
.gitlab-ci.yml
foobar.sh
this job:
job1:
stage: run
image:
name: my_image
script:
- ./foobar.sh
- some other scripts within the docker
can successfully run.
The log shows after pulling my_image, there's a git clone action, like what another SO answer said. but the log isn't detail enough to let me know where this command is triggered(I'm not the owner of gitlab ci runner so cannot control the log verbose level, if it matters).
So my questions:
Is this git clone command run within or outside the docker?
If within, who triggered it? what's the complete command of docker run ...?
If outside, when and where is the directory mounted to docker?
I have read the docs, but didn't find anywhere to explain above mechanism.
See, the gitlab runner pulls the image and spins up a container. Then from inside the container, a git clone of that gitlab repo is performed (by the gitlab runner). It's not from outside, and nothing is mounted. It works only with the repo where the pipeline belongs to.
If you wish to clone another repo, you have to do it manually by either baking it into your image upfront or telling the gitlab runner to perform another git clone.
script:
- git clone https://github.com/bluebrown/dotfiles
I assume, that when git is not installed in the container, it causes problems.

How can I upload my Dockerfile to Docker Hub when pushing an image through automated builds?

I setup docker automated build via Github and I can build an image successfully from a Dockerfile in my GitHub repository
I have followed the thread here and here
According to the documentation, if I do my build via an automated build connected to Github, all I need is to have my Dockerfile present and it will be added.
The builds succeeds, so the automation process works.
I can even see the Readme from GitHub in the registry. But for some reason, I can't see my Dockerfile in Docker hub.
Here is an example Github repo and here is the repository in Docker hub
Is there any more configuration necessary to get the Dockerfile to docker hub?
welcome Jungo!
TL;DR
You can learn more information about why on the Docker forum.

How to pull docker image from github and build image in ec2?

My actual requirement is pull docker image from GitHub and build a docker image in ec2 instance and push that image to ecr. So, am just trying to clear my first step by asking help to pull image from git, very new to all this.
Let's walk through each step you're asking about in your requirements:
Pull from GitHub - You won't pull a docker image from here, however you may pull a Dockerfile from here, which would be used to build an image. The command to do this would be just like cloning any other repository: git clone <repository url>
Build the image on ec2 - First you will need to have docker installed on the ec2 instance. Assuming you're running Ubuntu on your ec2 instance, follow the good instructions on Docker's page (https://docs.docker.com/install/linux/docker-ce/ubuntu/) miror. Once docker is installed, navigate to the directory that has your Dockerfile in it (cloned from git) and type docker build . --tag mytag
Push the image to ecr - To do this, you need to have the amazon CLI installed on your box, and you need an ACCESS_KEY_ID and SECRET_ACCESS_KEY from AWS IAM. Once you have these, configure your connection by storing them as environment variables, or by typing aws configure and entering them. Once your credentials are configured, log into ECR by typing aws ecr get-login --no-include-email, and then copy/pasting the command it gives you. (you can also put ` around it to skip the copying step). This will allow you to push to ecr using docker push.
To clarify some of the points:
Github: It is a web-based hosting service for version control using git. So you can not pull docker image from Github.
To build a Docker image, you need Dockerfile. So you can fork the GitHub project which has this Dockerfile.
Then to build it on ec2, you can check out the project containing Dockerfile on ec2 server and build it using:
https://docs.docker.com/engine/reference/commandline/build/
and then you can push it to any registry using:
https://docs.docker.com/engine/reference/commandline/push/

Resources