docker private image can not be pulled in centos7 - docker

I created a docker image and pushed to docker hub, then i changed it to private.
In my Mac, I can pull it after I issued "docker login" and entered all the info.
But in Cento7 (VM), this is no longer working, the private repository can not be found. I have to change the repo from private to public, then I can pull the image.
Why this happened? What do I need to do in order to pull a private repository from docker hub?
Thanks

create a new file .netrc to
#vim .netrc
machine github.com
login < your github token >
Add those 2 lines and pass your github token
Then copy the .netrc file to the container by including this line in dockerfile will pass credentials inside the docker containers and helps to pull more than one private repositories
COPY .netrc /root/

Related

Is there anyway to use github / gitlab for downloading the docker image?

Since Docker Hub only allows 1 private repo, I wonder if there is any way to use Github or Gitlab, etc., to download the images? for instance:
FROM git#github.com/username/repo
...
...
...
Very easy with an account on gitlab.com. GitLab provides a Docker registry linked to projects and you can have unlimited private projects:
Create a project my-docker-project
Go to Package and Registries > Container registries, you should see a few commands to access your registry
Connect your machine to this registry using a command like:
# Will prompt for login/pass
docker login registry.gitlab.com
You'll need an access token or deploy token with read_registry and write_registry scopes. You can generate one via your profile Preferences > Access token. Login is the token name and password the secret token provided.
You can now push Docker images with commands such as:
# Push an image
docker push registry.gitlab.com/YourUsernameOrGroup/my-docker-project
# Push an image on a sub-path
docker push registry.gitlab.com/YourUsernameOrGroup/my-docker-project/myimage
You can then use the image in a Dockerfile by referencing its URL such as:
FROM registry.gitlab.com/YourUsernameOrGroup/my-docker-project
# ...
Of course the machine from which you build must be authenticated on related GitLab registry using docker login command above (or the project must be public)
both have excellent package registry services
For GitHub GPR
For GitLab GCR
Both have excellent features like use it directly from Dockerfile as you want for example.
I have a public example, you can check it in Github with node.js which uses GPR to store the build image/package.

How to pull docker images from public registry and push it to private openshift?

I need to pull all images from an openshift template file, in my case it's openwhisk.
I'm trying to deploy this project on a private network so I don't have access to docker's official repository from there and thus need to push the images myself.
I was hoping there is a script/tool to automate this process.
There is no such available tool/script but you can write small shell script to do it.
If public dockerhub registry not allowed then either use private separate registry
or
Pull the image in your local laptop then tag it and push to openshift registry.
After pushing all the image to openshift, import your openshift template to deploy your application.
Below is the steps for single image. you can define list of image and loop it over the list.
docker pull imagename
oc login https://127.0.0.1:8443 --token=<hidden_token> #copy from https://your_openshift_server:port/console/command-line
oc project test
oc create imagestream imagename
docker login -u `oc whoami` -p `oc whoami --show-token` your_openshift_server:port
docker tag imagename your_openshift_server:port/openshift_projectname/imagename:tag
docker push your_openshift_server:port/openshift_projectname/imagename:tag
you can get more details on page suggested by graham-dumpleton
.
Graham Dumpleton's book talks about this. You create a list (JSON) of all the images used and import that into the openshift namespace. Since your OpenShift is offline/disconnected, you'll also change any remote registry to the URL of the internal, hosted registry.
Example that imports all JBoss images: https://github.com/projectatomic/adb-utils/blob/master/services/openshift/templates/common/jboss-image-streams.json

Use docker-compose to pull images from private repository

I'm using docker-compose command to run multiple containers. The problem is my docker-compose has to pull some images from the public repository and some from a private repository. What I'm planning to do is push all required images to the private repository but how can I make docker-compose pull the images from the private repository.
In short -> How to point to a private repository when the images are only available there
Use docker login command. (Official doc)
Enter your credentials, and then you can pull private image, only if you have an access.
If you want to login to a self-hosted registry you can specify this by adding the server name.
docker login localhost:8080
Thanks to #herm's comment, if you want to use swarm, use :
--with-registry-auth option.
Personnaly, I use this command :
docker stack deploy --with-registry-auth --compose-file dev.compose.yml myProjectName

Private Github repositories in dockerized rails application during build

I dockerized a new Rails 5 app with docker-compose.yml and I'm forwarding my ssh-agent socket into the container within the compose file.
If I build and run via docker-compose this is working fine, I can access the ssh key.
However, if I add bundle install to the build process, which fetches from private Git repositories and needs the SSH key, it's of course not yet available.
How can I solve this?
My current Dockerfile and docker-compose.yml files are:
https://gist.github.com/solars/d9ffbc4c570e9a128d6b0254268d785a
Thank you!
You need ~/.ssh/id_rsa to clone private repo into docker image.
One way: Copy your id_rsa and paste into docker image (~/.ssh/ location)
Other: you can create another temporary id_rsa (maybe run in a docker container and copy the .ssh file in your local machine). Copy the new .ssh folder into docker image (~/ location) alwasy when creating a docker image using Dockerfile. Next, Add you new .ssh/id_rsa.pub in your github account -> settings -> SSH and GPG keys -> new SSH key.
Working procedure: when you creating a new image, you are doing copy same .ssh folder inside image by Dockerfile, so id_rsa remaining same and the id_rsa.pub is added in your github account before. So, you are able to clone your private repo from your docker container always.

Unable to pull private repo in docker

I created an image for my application and uploaded it as private repository in registry.hub.docker.
Now I every time I try to pull it, I get the following error
FATA[0012] Repository not found
I have successfully authenticated myself with docker using docker login command
Command I ran
## docker login
docker login
Username (werain): werain
WARNING: login credentials saved in /Users/werain/.dockercfg.
Login Succeeded
## docker pull
docker pull werain/digitdem
Any Clue?
Use the full image name, including the tag, when pushing and pulling:
docker push werain/digitdem:latest
docker pull werain/digitdem:latest
Docker generally assumes you mean latest when you don't specify, but if you want to use your own tag or if you didn't push the same tag as you're trying to pull, then omitting the tag won't work.
Add .netrc file to the dockerfile will pass credentials inside the docker containers and helps to pull more than one private repositories to build dependencies
#vim .netrc
machine github.com
login < your github token >
Add those 2 lines and pass your github token
Then copy the .netrc file to the container by including this line
COPY .netrc /root/

Resources