Is there a way i can include .deb package in Docker file - docker

I created a xyz.deb package which, after installation, provides an application. I am trying to create a Docker container with FROM ubuntu:20.04.
How do I add my xyz.deb package in the Dockerfile and install it so that container comes ready with the application xyz.

The COPY command in a Dockerfile lets you copy external files into the container. You can then install the .deb file as you would on your local system with a RUN command.
Simple example:
COPY ./xyz.deb /
RUN dpkg -i /xyz.deb

Related

renaming a file with Dockerfile instructions

I'm trying to build a docker which clones a public repository, builds a library and the built library is then used by the main application. My local machine is on MacOS, the docker is a Linux distro, so I just can't compile and move the file. The library needs to be renamed (mandatory, the output is .dylib, but to use it in python it must become .so) and moved (optional).
ADD and COPY take my local machine as reference for the source, the relevant part of the Dockerfile is:
RUN git clone https://gitlab.com/somelib/somelib.git
RUN curl https://sh.rustup.rs -sSf | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"
RUN cargo build --release --manifest-path=somelib/Cargo.toml
RUN cp somelib/target/release/libsomelib.dylib app/main/util/somelib.so #<-- ERROR HERE
But this doesn't work because it fails to find libsomelib.dylib
cp: cannot stat 'somelib/target/release/libsomelib.dylib': No such file or directory
Is this possible or is docker not meant for this this operation?

How to download a file from URL using Dockerfile

I'm new to the docker world. I'm writing a docker file to install a certain library. The first step it does is download the library from a URL. I'm not sure if it's possible in docker.
I need to install the library on RedHat System.
http://service.sap.com/download is the URL I need to download the library. How can I write Dockerfile for the same?
Can someone please help?
Appreciate all your help! Thanks!
You run a RUN command depending on the programs availible in your system. If you have wget on your system, you just put the command in your dockerfile:
RUN wget http://your.destination/file
If you need that file to move to a location in your image, you keep using RUN command with mv, if the file is outside your image, you can use COPY command.
To resume, downloading your file from the system
[CLI] wget http://your.destination/file
[DOCKERFILE] COPY file .
Downloading a file with docker
[DOCKERFILE] RUN wget http://your.destination/file
[DOCKERFILE] RUN mv file my/destination/folder

Unable to run docker image on Windows desktop. Do I need different images if I want to run the images on windows and Linux

When I run my docker image, I get error as the image can't find a file which should be there.
Error
C:\Users\..\web>docker run mmy-app-1.0-snapshot:latest
Oops, cannot start the server.
ch.qos.logback.core.joran.spi.JoranException: Could not open URL [file:/deploy/my-app-1.0/logback_prod.xml].
My local machine is a windows 10 on which I want to test my docker image. Eventually, I'll install it on a virtual machine on google cloud. The image is of my play framework application which needs only java runtime only as per this document - https://www.playframework.com/documentation/2.5.x/Deploying
The distribution of the application will have two files in the zip, one for linux and other a .bat file for windows. I want to be able to run the linux version on my windows machine by using docker run. For this I plan to create a docker image of my application.
Question 1) Can I use Docker to create such an image which I can run both on my windows machine and on a linux machine in the cloud?
Question 2) Will I need to create two separate images for linux and windows?
I have installed docker desktop for windows from https://hub.docker.com/?overlay=onboarding. I have created the following Dockerfile.
FROM openjdk:8
ENV APP_NAME my-app
ENV APP_VERSION 1.0-SNAPSHOT
#make a directory deploy in the container
RUN mkdir deploy
#cd to container
WORKDIR deploy
#copy from host (path relative to location of Dockerfile on host) to deploy directory. The deploy directory will have my-app-1.0.zip, logback_prod.xml and application_prod.xml
COPY target/universal/my-app-1.0.zip .
COPY conf/logback_prod.xml .
COPY conf/application_prod.conf .
#unzip deploy/my-app-1.0.zip in container
RUN unzip my-app-1.0.zip
#chmod my-app script in deploy/my-app-1.0/bin/my-app
RUN chmod +x my-app-1.0/bin/my-app
#entrypoint is deploy/....
ENTRYPOINT my-app-1.0/bin/codingjediweb -Dplay.http.secret.key=changemeplease -Dlogger.file=logback_prod.xml -Dconfig.file=application_prod.conf
The dockerfile is at path web on my windows laptop. The same level has conf and target directories. I suppose in Dockerfile the WORKDIR is the path in the image and when I use COPY command, the first path (source) is the local path on my machine and the 2nd path (target) is the path in the image.
Question 3) when I run docker run my-app-1.0-snapshot:latest, I get the error stated at the beginning of the question. Why is the file not found? I notice the url is /deploy/..... As I had set the WORKDIR to ., shouldn't it be ./deploy?
The issue was that in ENTRYPOINT, I needed to specify the correct path - ENTRYPOINT my-app-1.0/bin/codingjediweb -Dplay.http.secret.key=changemeplease -Dlogger.file=deploy/logback_prod.xml -Dconfig.file=deploy/application_prod.conf
The WORKDIR is not used in -Dlogger.file and -Dconfig.file parameters it seems.

How to access local file when building from Dockerfile?

I need hello.rpm when I build from Dockerfile, but this rpm file is not available online.
Right now I'm serving the file by firing up a temporary web server, but ideally I'd like to run a build command which makes this local file available inside the container.
Is this possible?
My build command:
docker build -t fredrik/helloworld:1.0 .
My Dockerfile:
FROM centos:6
RUN rpm -ivh hello.rpm
Why don't you COPY the file inside the container before executing RUN?
FROM centos:6
COPY hello.rpm /tmp/hello.rpm
RUN rpm -ivh /tmp/hello.rpm
This assumes that hello.rpm is next to your Dockerfile when you build it.
Otherwise if an internet connection is not a limiting factor while you're working just:
Upload the file a cloud as Dropbox
Go to your docker shell and wget https://www.cloudnameXYZ.com/filename

How do I dockerize an existing application...the basics

I am using windows and have boot2docker installed. I've downloaded images from docker hub and run basic commands. BUT
How do I take an existing application sitting on my local machine (lets just say it has one file index.php, for simplicity). How do I take that and put it into a docker image and run it?
Imagine you have the following existing python2 application "hello.py" with the following content:
print "hello"
You have to do the following things to dockerize this application:
Create a folder where you'd like to store your Dockerfile in.
Create a file named "Dockerfile"
The Dockerfile consists of several parts which you have to define as described below:
Like a VM, an image has an operating system. In this example, I use ubuntu 16.04. Thus, the first part of the Dockerfile is:
FROM ubuntu:16.04
Imagine you have a fresh Ubuntu - VM, now you have to install some things to get your application working, right? This is done by the next part of the Dockerfile:
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y python
For Docker, you have to create a working directory now in the image. The commands that you want to execute later on to start your application will search for files (like in our case the python file) in this directory. Thus, the next part of the Dockerfile creates a directory and defines this as the working directory:
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
As a next step, you copy the content of the folder where the Dockerfile is stored in to the image. In our example, the hello.py file is copied to the directory we created in the step above.
COPY . /usr/src/app
Finally, the following line executes the command "python hello.py" in your image:
CMD [ "python", "hello.py" ]
The complete Dockerfile looks like this:
FROM ubuntu:16.04
RUN apt-get update && \
apt-get upgrade -y && \
apt-get install -y python
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
CMD [ "python", "hello.py" ]
Save the file and build the image by typing in the terminal:
$ docker build -t hello .
This will take some time. Afterwards, check if the image "hello" how we called it in the last line has been built successfully:
$ docker images
Run the image:
docker run hello
The output shout be "hello" in the terminal.
This is a first start. When you use Docker for web applications, you have to configure ports etc.
Your index.php is not really an application. The application is your Apache or nginx or even PHP's own server.
Because Docker uses features not available in the Windows core, you are running it inside an actual virtual machine. The only purpose for that would be training or preparing images for your real server environment.
There are two main concepts you need to understand for Docker: Images and Containers.
An image is a template composed of layers. Each layer contains only the differences between the previous layer and some offline system information. Each layer is fact an image. You should always make your image from an existing base, using the FROM directive in the Dockerfile (Reference docs at time of edit. Jan Vladimir Mostert's link is now a 404).
A container is an instance of an image, that has run or is currently running. When creating a container (a.k.a. running an image), you can map an internal directory from it to the outside. If there are files in both locations, the external directory override the one inside the image, but those files are not lost. To recover them you can commit a container to an image (preferably after stopping it), then launch a new container from the new image, without mapping that directory.
You'll need to build a docker image first, using a dockerFile, you'd probably setup apache on it, tell the dockerFile to copy your index.php file into your apache and expose a port.
See http://docs.docker.com/reference/builder/
See my other question for an example of a docker file:
Switching users inside Docker image to a non-root user (this is for copying over a .war file into tomcat, similar to copying a .php file into apache)
First off, you need to choose a platform to run your application (for instance, Ubuntu). Then install all the system tools/libraries necessary to run your application. This can be achieved by Dockerfile. Then, push Dockerfile and app to git or Bitbucket. Later, you can auto-build in the docker hub from github or Bitbucket. The later part of this tutorial here has more on that. If you know the basics just fast forward it to 50:00.

Resources