docker create Linux with my own application - docker

I developed an HTTP server which implements RESTful API specified by our client. Currently my workstation (Centos 7.4 x86_64) and everything else is working. Now I need to ship it as Centos 7.4 docker image.
I read the getting started guide and spent some time browsing the documentation but am still not sure how to proceed with this.
Basic Steps
Download Centos image from here
Run Centos image on my workstation and copy everything into it.
Make an appropriate changes so that server is started via systemd.
In step 3 : I am not sure how to do root/sudo inside the docker image.

I think what you are looking for is the Dockerfile reference https://docs.docker.com/engine/reference/builder/#understand-how-arg-and-from-interact
It's a file name Dockerfile that sits in the root of your project. You specify in this file which commands you want to run on top of the base image.
for example, from your use case:
FROM centos7.4.1708
COPY <your files> /opt/
CMD ["program.exe" "-arg" "argument"]
FROM - defines the base image
COPY - copies files from the folder you run the command from to the image
CMD - runs this command when the container starts
Build with docker build . -t image-name
Run with docker run image-name

Related

Nextcloud docker image rebranding

I want to use the nextcloud image from dockerhub as the base image for the purpose of creating the a new child image having my own company's logo in place of nextcloud and my preferred background colour.Can anyone help me with the process or any link to the solution to this?
https://nextcloud.com/changelog
-download this zip
-make a docker file
-your should install apache and setup it
-change logo and colour theme in your css file
-built a new image
The general approach is this:
Run the official image locally, follow the instructions on Docker Hub to get started.
Modify the application using docker and shell commands. You can:
open a shell (docker exec -it <container> sh) in the running container and use console commands to edit files;
copy files from from the container and back with docker cp;
mount local files into the container by using -v <src>:<dest> in docker run command.
When you're done with editing, you need to repeat all the steps in a Dockerfile:
# use the version you used to start the local container
FROM nextcloud
# write commands that you used inside the container (if any)
RUN echo hello!
# Push edited files that you copied/mounted inside
COPY local.file /to/some/place/inside/the/image
# More possible commands in Dockerfile Reference
# https://docs.docker.com/engine/reference/builder/
After that you can use docker build to create your modified image.

Running attended installer inside docker windows/servercore

I've been attempting to move an application to the cloud for a while now and have most of the services set up in pods running in a k8s cluster. The last piece has been giving me trouble, I need to set up an image with an older piece of software that cannot be installed silently. I then attempted in my dockerfile to install its .net dependencies (2005.x86, 2010.x86, 2012.x86, 2015.x86, 2015.x64) and manually transfer a local install of the program but that also did not work.
Is there any way to run through a guided install in a remote windows image or be able to determine all of the file changes made by an installer in order to do them manually?
You can track the changes done by the installer following these steps:
start a new container based on your base image
docker run --name test -d <base_image>
open a shell in the new container (I am not familiar with Windows so you might have to adapt the command below)
docker exec -ti test cmd
Run whatever commands you need to run inside the container. When you are done exit from the container
Examine the changes to the container's filesystem:
docker container diff test
You can also use docker container export to export the container's filesystem as a tar archive, and then docker image import to create an image from that archive.

How to add docker support for an Angular 7 application using VS2017?

I created an Angular 7 application using VS2017 by following this documentation. The application is working fine in local machine, but I want to add docker support for this angular application, and also deploy it into either local docker or local kubernetes.
So, can anyone help on that issue?
I do not know the book that you referenced. But in general the steps would be:
- Try to run your application locally from command line (I guess it can be started with dotnet run).
- Create a Dockerfile
- Use official docker images that already include dotnet framework as Base-Image (e.g.: from microsoft/dotnet:runtime)
- In your Dockerfile you can add as much as you want (install dependencies, run unit-tests, etc.), but to keep it simple the following should be enough:
Dockerfile:
from microsoft/dotnet:runtime
COPY . .
RUN dotnet restore
RUN dotnet build
ENTRYPOINT ["dotnet", "run"]
To optimize for performance you can use multi-stage docker images and split your Dockerfile into build and runtime
Note, that I didn't read your tutorial, but this is how I would start with preparing for docker
To work with kubernetes you can simply push your docker image (docker build -t <your-tag>) to a docker-registry, which your kubernetes cluster has access to and create a k8s-deployment for that contains that image. Locally you don't need a docker-registry but can simply kubectl run ...
See:
https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
and https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/

How to prepare a blank website to be dockerized?

I have a totally empty debian9 on which I installed docker-ce and nothing else.
My client wants me to run a website (already done locally on my PC) that he can migrate/move rapidly from one server to another moving docker images.
My idea is to install some empty docker image, and then install on it manually all dependencies (ngingrtmp, apache2, nodejs, mysql, phpmyadmin, php, etc...)
I need to install all these dependencies MANUALLY (to keep control) - not using a ready to go docker images from dockerhub, and then to create an IMAGE of ALL things I have done (including these dependencies, but also files I will upload).
Problem is : I have no idea how to start a blank image, connect to it and then save a modified image with components and dependencies I will run.
I am aware that the SIZE may be bigger with a simple dockerfile, but I need to customize lots of things such as using php5.6, apache2.2, edit some php.ini etc etc..
regards
if you don't want to define you're dependencies on the docker file then you can have an approach like this, spin up a linux container with a base image and go inside the docker
sudo docker exec -it <Container ID> /bin/bash
install your dependencies as you install on any other linux server.
sudo apt-get install -y ngingrtmp apache2 nodejs mysql phpmyadmin php
then exit the container by ctrl+p and ctrl+q and now commit the changes you made
sudo docker commit CONTAINER_ID new-image-name
run docker images command and you will see the new image you have created, then you can use/move that image
You can try with a Dockerfile with the following content
FROM SCRATCH
But then you will need to build and add the operating system yourself.
For instance, alpine linux does this in the following way:
FROM scratch
ADD rootfs.tar.xz /
CMD ["/bin/sh"]
Where rootfs.tar.xz is a file of less of 2MB available on alpine's github repository (version 3.7 for x86_64 arch):
https://github.com/gliderlabs/docker-alpine/tree/61c3181ad3127c5bedd098271ac05f49119c9915/versions/library-3.7/x86_64
Or you can begin with alpine itself, but you said that you don't want to depend on ready to go docker images.
A good start point for you (if you decide to use alpnie linux), could look like the one available at https://github.com/docker-library/httpd/blob/eaf4c70fb21f167f77e0c9d4b6f8b8635b1cb4b6/2.4/alpine/Dockerfile
As you can see, A Dockerfile can became very big and complex because within it you provision all the software you need for running your image.
Once you have your Dockerfile, you can build the image with:
docker build .
You can give it a name:
docker build -t mycompany/myimage:1.0
Then you can run your image with:
docker run mycompany/myimage:1.0
Hope this helps.

What is the step by step process to deploy a java app to Docker?

I've engineering background mostly with coding/dev't than deployment. We have introduced Microservices recently to our team and I am doing POC on deploying these Microservices to Docker. I made a simple application with maven, Java 8 (not OpenJdk) and jar file is ready to be deployed but I stuck with the exact steps on how to deploy and run/test the application on Docker container.
I've already downloaded Docker on mac and went over this documentation but I feel like there are some steps missing in the middle and I got confused.
I appericiate your help.
Thank you!
If you already have a built JAR file, the quickest way to try it out in docker is to create a Dockerfile which uses the official OpenJDK base image, copies in your JAR and configures Docker to run it when the container starts:
FROM openjdk:7
COPY my.jar /my.jar
CMD ["java", "-jar", "/my.jar"]
With that Dockerfile in the same location as your JAR file run:
docker build -t my-app .
Which will create the image, and then to run the app in a container:
docker run my-app
If you want to integrate Docker in your build pipeline, so the output of each build is a new image, then you can either compile the app inside the image (as in Mark O'Connor's comment above; or build the JAR outside of the image and just use Docker to package it, like in the simple example above.
The advantage of the second approach is a smaller image which just has the app without the source code. The advantage of the first is you can build your image on any machine with Docker - you don't need Java installed to build it.

Resources