How can I make an image from the current environment to share docker hub? - docker

I have some services running when I run docker-compose up command. Now I want to make an image from the current environment and share it with docker hub so that every time I can use docker pull/run my_own_image command from the docker hub.
Is there any way to do that?

Pretty much anything that you can do with images or containers with Docker, you can do with Compose. In your case, since you can push your custom image to your Docker Hub registry using docker image push (or docker push) command, you can do the same with Compose.
As for Compose, you use docker-compose push (no surprises there – consistency between APIs/CLIs).
Tip: when in doubt, use --help. It's the best way (next to Google) to explore CLI. If not sure what are available commands/options for Compose, just type docker-compose --help. If you want to see available options for push command (for example), use docker-compose push --help.

Related

How do I docker buildx build into a local "registry" container

I am trying to build a multi-arch image but would like to avoid pushing it to docker hub. I've had a lot of trouble finding out how to control the export options. is there a way to make "--push" push to a registry of my choosing?
Any help is appreciated
Docker provides a container image for a registry server that you may self run even on localhost, see: Deploying a registry server.
There are other servers|services that implement the registry API (see below) but this is a good place to start.
Conventionally, images pushed|pulled default to Docker registry; unless a registry is explicitly specifed, an image e.g. your-image:your-tag defaults to docker.io/my-image:my-tag. In my opinion, it's a good practice to always include this default to be more transparent about this.
If you run Docker's registry image on localhost on the default port 5000, you'll need to take your images with localhost:5000/your-image:your-tag to ensure that when you docker push localhost:5000/your-image:your-tag, the CLI is able to determine your local registry is the intended destination.
Similarly, if you use e.g. Quay registry, images must be prefixed quay.io, Google Artifact Registry, images are prefixed ${REGION}-docker.pkg.dev/${PROJECT}/${REPOSITORY} etc.
IIRC it's not possible to push to Docker's registry (aka dockerhub) without an account so, as long as you ensure you're not logged in, you should not accidentally push images to Docker's registry.
NOTE You only need to use a registry to ease distribution of container images between machines. If you're only interested in local(host) development, you can docker run ... immediately after a successful docker build without any pushing|pulling (beyond interim images, e.g. FROM).

Push existing image to another registry (without mounting docker.sock or using docker:dind)

Is it actually posible to push the existing image to another docker registry without either mounting docker.sock or starting docker:dind?
I'm running docker build in cluster (with kaniko) and the image needs to be pushed to another repository.
I haven't found an option for kaniko to do that. The only way would be to start a new build (am I correct?).
Is there another alternative? Pulling and pushing should be actually easier as building, and should not require access to the docker daemon?
The docker registry has a documented API, and OCI is close to finishing their distribution-spec release, so it's possible to interact with the registry directly rather than using the docker engine. I've been doing exactly that with regclient that includes a regctl image copy command that likely does exactly what you're looking to achieve.

Make Nginx image available in local/private repository for production safe perspective in kubernetes

How can we make nginx image available in my local/private repository in kubernetes?
Lets say i am using nginx image tag version x.x. I have tested it in my dev and test env and want to move it to prod.
What if the image is not present in nginx repository?
Is there a way to pull the x.x version of nginx to our local/private repository?
There is a high risk if the image is not available. So it would be helpful if anyone guide me how we handle this.
If you have docker installed in your machine, pull docker image
$ docker pull nginx:x.x
Now, you can't use this local docker image inside Kubernetes. You need to do additional thing
Push this image into your docker registry in cloud.
$ docker tag nginx:x.x <your-registry>/nginx:x.x
$ docker push <your-registry>/nginx:x.x
And then use <your-registry>/nginx:x.x from your registry.

Docker - is it necessary to push images to remote server?

I have successfully built some Docker images:
Now I would like to start my microservices by docker-compose, unfortunatelly I am unable to pull those images i.e. repository callista/discovery-server not found: does not exist or no pull access I solved this error by logging into my DockerHub account and pushining those images to remote server. But it seems to me like a little overkill to send such larges images (which are likely to change pretty soon) over the Internet over and over again twice (push&pull).
Is it possible to configure Docker to install those images locally and not to pull from remote server?
I use Docker 1.8 and work on Windows 10.
Do you need to run this images in a server different from the one you build then?
If you need you have some alternatives:
As #engineer-dollery said, you can run a registry into your network, than you would not need to send it over the internet, only in your network. Docs: https://docs.docker.com/registry/deploying/
You could use the docker save and docker import to move then around too. Docs: https://docs.docker.com/engine/reference/commandline/save/
But if the server you run the images is the same you build then...
...than you could just add the tag image to your docker-compose services, and do a docker-compose build, as #lauri said, but with the image docker-compose will create a image with that name after the build, and then you could do docker run using than. Or do a docker-compose up --build so it will always build than again if something changes into the Dockerfile
If you define build option in docker-compose.yml, you should be able to build images locally with Docker Compose and then it uses those images without pulling. By default Docker Compose builds images if they are not found locally. If you want to rebuild images just add --build option docker-compose up command docker-compose up --build
Docker Compose build reference:
https://docs.docker.com/compose/compose-file/#build

How I use a local container in a swarm cluster

A colleague find out Docker and want to use it for our project. I start to use Docker for test. After reading an article about Docker swarm I want to test it.
I have installed 3 VM (ubuntu server 14.04) with docker and swarm. I followed some How To ( http://blog.remmelt.com/2014/12/07/docker-swarm-setup/ and http://devopscube.com/docker-tutorial-getting-started-with-docker-swarm/). My cluster work. I can launch for exemple a basic apache container (the image was pull in the Docker hub) but I want to use my own image (an apache server with my web site).
I tested to load an image (after save it in a .tar) but this option isn't supported by the clustering mode, same thing with the import option.
So my question is : Can I use my own image without to push it in the Docker hub and how I do this ?
If your own image is based on a Dockerfile that you build you can execute the build command on your project while targeting the swarm.
However if the image wasn't built, but created manually you need to have a registry in between that you can push to, either docker hub or some other registry solution like https://github.com/docker/docker-registry

Resources