Docker: Push data container onto Docker Hub - docker

I am really new at this Docker stuff, and even newer at Docker Hub, so please bear with me …
I have created a data container to use with my docker image (specifically, a data container to store data for a running mssql-server-lnux image). I know where it is on my local system.
I have a newly created account on Docker Hub and I think I want to push the data container on the hub. I say I think because I’m not sure that it’s the right way to go about it: I want to be able to use the data container from different machines.
If what I have said so far is in the right direction, then how do I push the docker image to the Hub, and how do I then access it later?

You can't push containers, only images, the distinction is important.
Image is akin to a class of your container, and container is essentially an instance of your image.
So if you want to push to share your database then it's not a good idea - you would have to docker commit first and this would get ugly really fast.
But if you just want to start new instances of your mysql on different machines with fresh data containers (there will be no data initially) then go ahead and push the data container image.
Hope this helps.

Okay, here are few steps. Please check if this helps.
Tag your image first. Let's say your image name is 'myapplication' and your docker hub user name is 'dockerhubusername'.
$ docker tag myapplication dockerhubusername/myapplication
Login to docker hub using. Enter user name like 'dockerhubusername' and then password of docker hub account.
$ docker login
Now push command.
$ docker push dockerhubusername/myapplication
Now, login to your docker hub and check if you have image there. Remember, images are pushed to registry/repository like dockerhub not containers.

Assuming you have tagged your image,
Use docker login to configure your docker hub credentials and use docker push to push your image to dockerhub.
$ docker login
$ docker push dockerhub_username/mssql-server-lnux
If you have not yet tagged the image,
$ docker tag mssql-server-lnux dockerhub_username/mssql-server-lnux
To access your image later,
$ docker pull dockerhub_username/mssql-server-lnux
References
Docker Pull
Docker Login

Related

How to access the locally built docker-image on the docker-swarm manager?

While trying to build a service on docker-machine i got an error of "image doesn't exist" on that docker-machine manager node. As I checked the docker images command on the manager node, no image was there as expected. But on the root docker side I have those images. I want to access these images on the manager node. I've read few articles where it was mentioned that, maybe I've to upload that image on the docker hub then pull it from that hub. But I want to access it locally. Is there any way to do this as I'm newbie to docker.
This is the command what I tried on my manager machine:
docker#manager:~$ docker service create --name "api-client" -p 4200:4200 api_client
This is my docker images output:
REPOSITORY TAG IMAGE ID CREATED SIZE
api_client latest 097b19c4deb8 27 hours ago 1.15GB
But on my docker#manager terminal, my docker image folder is empty.
The problem is that there is no repository to hold the image. The repository needs to be pulled from to a repository to each node in the Swarm before it can execute. In general you need to do the following:
Setup a repository, if you want a local repository there is a guide here, but it will be some hassle to get it up and running i and "insecure http" version. An easier way is to get yourself a free docker hub account and put your image there.
Tag your local image with the repository name. Howto is shown in the guide above.
docker tag <local image> <repository>/<image:tag>
Login to the repository (if in cloud) and push your image to the repository
docker login
docker push <repository>/<image>:<tag>
To run the image (your command)
docker service create --name "api-client" -p 4200:4200 <repository>/<image>:<tag>
Your can also try to pull an image into the local cache of a node using
docker pull <repository>/<image>:<tag>

Awaiting gcloud docker -- push

Im building a deployment script in nodejs, with 1 part being calling the gcloud cli through require('child_process').spawn(...); to push the already build docker images. i execute the following command:
gcloud docker -- push myImage
This all works great, the images gets uploaded. But the problem is that gcloud docker opens a new process to push my image and the process i spawned, closes before the pushing of the image is done.
Problem is, I want to delete the builded images locally, directly afterwards.
I've been looking in the gcloud docker documentation but i don't see any argument for this.
Is there a way to know that the process of uploading the images was completed?
edit:
i did find a way to do it only through docker but i'd like a universal solution (both working on windows and linux environments)
After some more research on the google documentation, i found this authentication page
They tell you to create a service account and use the json private key you get as token to use into docker login. This way you don't need an oauth token for your automated services, but you can use this json key instead.
You can check all the images by running this command:
[sudo docker images]
Take a note of the "IMAGE ID" it will used when Tagging and deleting the image.
When you build a docker images, tag it before By running this command:
[docker tag "IMAGE ID" gcr.io/{the Google Container Registry path}:{version} ]
You can push any built image by running this command:
[gcloud docker -- push gcr.io/{the google container registry path}:{version}].
When pushing you will notice that list of container are pushed to your Google Container registry see the example below:
$ sudo gcloud docker -- push gcr.io/{the google container registry path}:{version}
The push refers to repository [gcr.io/{the google container registry path}]
43d35f91f441: =================> Pushed
3b93beb428bf: Layer already exists
629fa6a1373d: =================> Pushed
0f82335d5733: Layer already exists
c216b39a9ab6: Layer already exists
ccbd0c2af699: Layer already exists
38788b6810d3: Layer already exists
cd7100a72410: Layer already exists
v1: digest: sha256:**************************************************************** size: 1992
You can check all the images by running this command:
[sudo docker images]
Take a note of the "IMAGE ID" of the image you need to delete.
Run the command :
[sudo docker rmi "IMAGE ID"].
If the image doesn't allow to be deleted, you have to stop the container that is still running and prune the docker
[sudo docker container stop "the container ID"]
[sudo docker container prune]
Then you can delete the image.

Docker show current registry

In docker, how can one display the current registry info you are currently logged in? I installed docker, if I now do docker push, where does it send my images?
I spend over 30min searching this info from Google and docker docs, and couldn't find it, so I think it deserves its own question.
There's no concept of a "current" registry - full image tags always contain the registry address, but if no registry is specified then the Docker Hub is used as the default.
So docker push user/app pushes to Docker Hub. If you want to push it to a local registry you need to explicitly tag it with the registry address:
docker tag user/app localhost:5000/user/app
docker push localhost:5000/user/app
If your local registry is secured, you need to run docker login localhost:5000 but that does not change the default registry. If you push or pull images without a registry address in the tag, Docker will always use the Hub.
This issue explains the rationale.
The way docker images work is not the most obvious but it is easy to explain.
The location where your images will be sent to must be define in the image name.
When you commit an image you must name it [registry-IP]:[registry-port]/[imagepath]/[image-name]
If you already have the image created and you want to send it to the local registry you must tagged it including the registry path before you push it:
docker tag [image-name] [registry-IP]:[registry-port]/[image-name]
docker push [registry-IP]:[registry-port]/[image-name]

clone docker images from local server?

I was wondering if there was a way to clone images from a local server.
The servers running containers will be hosted behind a bandwidth constrained connection. It would be great if there was a way to pull given containers for one server and then pull from that initial local server to update the containers on the remaining servers.
You could pull those images you want, give hem a new tag, and put them in your own registry.
For instance, let's say you pulled down the official registry image and stood it up at myregistry.internal.mycompany.com. Now, if you wanted to have a CentOS image available for all of your servers but didn't want to pull them all from the official repo (incurring the bandwitch charges) then you could pull a CentOS image (let's say centos:latest - docker pull centos) and then give that image a new tag, like this:
docker tag centos:latest myregistry.internal.mycompany.com/centos:latest
Now from your other servers you just pull 'myregistry.internal.mycompany.com/centos:latest'
Setting up your own repo is really easy as a docker container itself. You can pull the image and learn more at https://registry.hub.docker.com/_/registry/
I think you have a few options. If what you actually want to manage is images rather than containers:
You could set up a private Docker registry, and then push to/pull from that local repository. This may ultimately be the easiest if that is something that you want to do fairly often, because you're just using standard docker push/docker pull commands.
You could use docker save to save images on one server and docker load to load the images on another server.
If you are actually trying to move containers around:
You could use docker export on one server and docker import on another server.

Is it possible using the Docker remote API to copy an image to another host?

Supposed I have two servers, let's call them A and B. Both run Docker as daemon, and I have created an image on A.
So, of course, I am able to run this image as a container on host A.
Supposed I want to move that image to B - how do I do this? Is this possible via Docker's remote API? Or by any other way?
Right now, you can use docker save, scp, then docker load.
Alternatively, you can docker push then docker pull.
If you are not confortable using the public index, you can spawn a private registry. Take a look at https://github.com/dotcloud/docker-registry. The easiest way to do so is docker run stackbrew/registry. You will have more details on the github readme.

Resources