How to download a file from URL using Dockerfile - docker

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

Related

Downloading Large Files Inside A Docker Container

A simple problem that I am facing. I am using docker to build a simple image which downloads a file using curl or wget after container is loaded. The file that I am downloading is about 7GB and need 7GB more to extract it in the same container. Below is the code for the image I am building.
FROM node:alpine3.15 as builder
RUN apk update
RUN apk add wget
RUN apk add unzip
COPY package.json ./
COPY index.js ./
ADD startCensusLoad.sh .
RUN npm install
ENTRYPOINT ["/bin/sh","startProcess.sh"]
And this is my startProcess.sh file code.
wget --continue zip_file_download_link_goes_here;
unzip downloaded_zip_file.zip;
npm start;
When I build the image and start a container, the download starts as expected but stops at multiple points like 2 GB or 4 GB or 1.8 GB and so on. I have not been able to download the full file in the container yet. I have also tried curl and seeing the same behavior. Any suggestion on how to solve this issue. The container would run in a kube environment later on so that I can assign an ephemeral volume but for now I am trying to download full file in the container itself.
I was able to resolve this by doing more search on the census website. I was able to find that census.gov does provide that 7GB data in States level and I was able to use download a chunk at a time and process it. So basically container size did not exceed more than the largest state data.

EasyOCR on docker

I created a Docker image that has a flask app that uses EasyOCR. When you run the docker app on a port, and the script calls the EasyOCR module, it starts downloading the character recognition model, which crashes and terminates the container. Is there a way I can copy the model to the docker file already, so it doesn't have to do that once I have to run it?
I was with the same problem, and found the solution on the issues from EasyOCR: https://github.com/JaidedAI/EasyOCR/issues/706
Basically, you need to custom your Dockerfile like this:
RUN wget https://github.com/JaidedAI/EasyOCR/releases/download/v1.3/english_g2.zip
RUN wget https://github.com/JaidedAI/EasyOCR/releases/download/pre-v1.1.6/craft_mlt_25k.zip
RUN mkdir ~/.EasyOCR
RUN mkdir ~/.EasyOCR/model
RUN unzip english_g2.zip -d ~/.EasyOCR/model
RUN unzip craft_mlt_25k.zip -d ~/.EasyOCR/model
This will download them manually from the model hub and put them in the '~/.EasyOCR/model' folder
To see every model and choose what you need, follow to this link: https://www.jaided.ai/easyocr/modelhub/

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

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

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