How deploy docker-compose.yml on Docker hub? - docker

I built docker-compose.yml file. After building of it there was created new image. But this image isn't complete because the app doesn't work after running it. So. the app works only when run docker-compose up. I want to deploy the project to Docker hub. I found the solution with nginx. Please tell me how it's possible without third apps (e.g. nginx) and if the image doesn't work?

You don't.
DockerHub is service where you can share container images. If you created a custom Dockerfile specific for your application, then yes you could build an image for it and publish it either in a private or public repository. For creating images, check the Dockerfile best practices section.

Add sample docker-compose.yaml to README.md and push it to docker registry using docker-pushrm as shown in docker-pushrm documentation:
$ ls
Dockerfile README.md
$ docker login
Username: my-user
Password: ********
Login Succeeded
$ docker build -t my-user/hello-world .
$ docker push my-user/hello-world
$ docker pushrm my-user/hello-world
Dockerfile, example docker-compose.yaml and other getting-started instructions usually shared by README.md. E.g. Dockerhub can render and display documentation in Markdown format.

Related

Which command should I use to build and push my entire dockerised app and its services to docker hub? docker or docker-compose?

I am a little bit confused when using docker and docker-compose:
With dockerfile I can build, run, and push the docker application image to docker hub in order to allow other people to download and run it on their local computers.
With Docker-compose I can build, run and push the service image ( eg: redis, cassandra, etc)
My concern:
I got an application folder with the following files:
- main.go # the main app in Golang
- Dockerfile # container definition file
- Docker-compose.yml # contains all the services ( Redis and Cassandra)
which command should I use to build and push my entire app and its services on the docker hub? docker or docker-compose?
One useful conceptual way to think about this is that the docker-compose.yml file specifies a set of docker build and docker run commands. You cannot separately push the docker-compose.yml file to Docker Hub or other registries, and in a typical Compose setup there are references a number of standard images you don't need to push yourself (the standard Docker Hub redis and cassandra images will be fine no matter where you run them).
This means you need to do two things:
Push the application image (but not its public-image dependencies) to a registry; and
Publish the docker-compose.yml file or another way to run the combined application.
You can use docker-compose push, but in a CI environment it's probably a little more straightforward to use docker build and docker push. Mechanically they're not any different.
Make sure your image contains everything that's needed to run your application, up to external dependencies. The ideal is to be able to docker run your application container, with --net, -e, and -p settings to configure it, but without separately providing the application code or a command. In a docker-compose.yml file see if you can run it with only ports:, environment:, and image: (and build:). Prefer a CMD in the Dockerfile to a command: in docker-compose.yml. If you're bind-mounting host code into the container (unlikely for Go and other compiled languages) delete those volumes:.
A typical sequence for deploying things using Compose might look like:
here$ docker build -t me/myapp:20200525 .
here$ docker push me/myapp:20200525
here$ scp docker-compose.yml there:
here$ ssh there
there$ MYAPP_TAG=20200525 docker-compose up -d
Note that the only thing we directly copied to the target system is the docker-compose.yml that specifies how to run the image; we have not copied any application code or other dependencies, since that is all encapsulated in the image.

Import an image from an archive

I need to deploy selenium/standalone-chrome image to docker.
The problem is that I use corporative openshift with private registry. There is no possibility to upload image to registry or load it thru the docker (docker service is not exposed).
I managed to export tar file from local machine using command 'docker save -o'. I uploaded this image to artifactory as an artifact and now can download it.
Question: how can I create or import image based on a binary archive with layers?
Thanks in advance.
Even you're using OpenShift, you can proceed to Docker push since the registry is exposed by default: you need your username (oc whoami) along with the token oc whoami --show-token.
Before proceeding, make sure you have an Image Stream since it's mandatory in order to push images.
Once obtained these data, proceed to login from your host:
docker login -u `oc whoami` -p `oc whoami --show-token` registry.your.openshift.fqdn.tld:443
Now, you just need to build your image
docker build . -t registry.your.openshift.fqdn.tld:443/your-image-stream/image-name:version
Finally, push it!
docker push registry.your.openshift.fqdn.tld:443/your-image-stream/image-name:version

Docker: How to get docker image to GitHub

I built a docker image like this:
sudo docker image build -t docker_image_gotk3 .
If I execute
sudo docker images I can see the line:
REPOSITORY TAG IMAGE ID CREATED SIZE
docker_image_gotk3 latest c13f7fcdb11d 14 minutes ago 20.4MB
I searched the complete file system and I didn't find a single file named docker_image_gotk3. How do I actually get it?
You have to export the docker image to push GitHub.
docker save -o docker_image_gotk3.tar docker_image_gotk3
ls -sh docker_image_gotk3.tar
20.4M docker_image_gotk3.tar
Github doesn't appear to have a Docker registry service as of now.
Maybe you could try tracking your image in Docker Hub as an alternative to what Tibi02 proposes?
Just create an account at https://hub.docker.com/ if you don't have one already, and do the following:
docker login in your terminal to authenticate in Docker Hub
docker image push your_username/docker_image_gotk3:latest to upload your image to the registry
Then you should be able to see it at https://cloud.docker.com/repository/docker/you_username/docker_image_gotk3, and download your image with docker image pull your_username/docker_image_gotk3:latest
Hope this helps!

Questions on Docker Build and Local Docker Repo

I am trying to create a docker image using the below command .
docker build -t mytestapp .
My DockerFile looks like this
# Set the base image
FROM rhel7:latest
USER root
# Dockerfile author / maintainer
MAINTAINER Name <email.id#example.com>
# Update application repository list and install the Redis server.
RUN mkdir /usr/local/myapp/
ADD myapp-0.0.1-jar /usr/local/myapp/
RUN java -Dspring.profiles.active=qa -jar /usr/local/myapp/myapp-0.0.1.jar
# Expose default port
EXPOSE 8080
Questions:
1) Is it fine the way I am adding the JAR file. Will it be available inside /usr/local on the container after I prepared am image from the above build.
2) When I build the image using docker build command , is the build image is pushed to docker repository hub by default.
Since the WAR file contains credentials, I don't want to push the image to Docker Hub but we would like to push to our local Docker registry using Docker distribution and pushing with docker push.
Please clarify.
Answering your questions:
Docker recommends using the COPY instructions for adding single files into an image. It will be available inside the container at /usr/local/myapp/myapp-0.0.1-jar
When you build the image it will be available on your local docker-host. It won't leave the server unless you explicitly tell it so.
Another tip I want to give you is the recommended docker image naming convention, which is [Repository/Author]/[Imagename]:[Version].
So for your image it might be called zama/mytestapp:1.0
If you want to push it into your local registry, you'll have to name your image after the syntax [LocalRegistry:Port]/[Repository/Author]/[Imagename]:[Version].
So your image might now be called registry.example.com:5000/zama/mystestapp:1.0
If you have authentication on your registry, you need to docker login first and then simply push the image with docker push registry.example.com:5000/zama/mystestapp:1.0.

How to convert docker-compose setup to docker image?

How to convert docker-compose setup to docker image?
So i have a docker enviroment setup with docker-compose and i would like to create a docker image for Docker Hub from that setup.
Is there a way of doing this ?
No, you can't merge multiple images.
You can capture running containers as images with docker commit, and push each image to the Hub - but you'd need to share your docker-compose.yml separately.
There is a new workflow for this type of scenario called application bundles, which lets you capture a distributed system as a bundle of images. It's currently an experimental feature.
You can either build the image with $ docker build command and use the correct tag and push it with $ docker push. Or you can define the correct image in docker-compose.yml:
container:
build: .
image: username/image:tag
And after the build push the image with $ docker-compose push

Resources