How to pre-resize an existing application ... basics

I watched a ton of YouTube videos and read all the docker docs. However, I still do not understand the basic concept that prevents me from understanding docker. I use windows and boot2docker is installed. I downloaded images from a docker hub and ran basic commands. BUT How to get an existing application sitting on my local computer (just say that for simplicity it has one index.php file). How to take this and put it in the docker image and run it?

+5
source share
5 answers

Your index.php is not really an application. The application is your Apache or nginx or even your own PHP server.

Since Docker uses features not available in the Windows kernel, you run it inside a virtual machine. The sole purpose of this would be to train or prepare images for your real server environment.

Docker needs to understand two basic concepts: images and containers.

An image is a template made up of layers. Each layer contains only the differences between the previous level and some autonomous system information. Each layer is an image. You should always make your image from an existing database using the FROM directive in the Dockerfile ( Reference documents during editing Link Jan Vladimir Mostert is now 404).

A container is an instance of an image that is already running or running. When creating a container (aka run the image), you can map the internal directory to it from the outside. If there are files in both places, the external directory overrides the one inside the image, but these files are not lost. To restore them, you can bind the container to the image (preferably after stopping it), and then start a new container from the new image without displaying this directory.

+10
source

First you will need to create a docker image using dockerFile, you would probably install apache on it, tell dockerFile to copy the index.php file into your apache and set the port.

See http://docs.docker.com/reference/builder/

See my other question for an example docker file: Switching users inside a Docker image to a non-root user (this is for copying via a .war file to tomcat, similar to copying a .php file to apache)

+2
source

Imagine you have the following existing python2 application "hello.py" with the following contents:

print "hello" 

You must follow these steps to dockerize this application:

Create the folder where you want to save the Docker file.

Create a file called "Dockerfile"

A Dockerfile consists of several parts that you must define as described below:

Like a virtual machine, the image has an operating system. In this example, I am using ubuntu 16.04. Thus, the first part of the Docker file:

 FROM ubuntu:16.04 

Imagine you have a new Ubuntu - VM, now you need to install some things to make your application work, right? This is done using the following part of the Docker file:

 RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y python 

For Docker, you need to create a working directory on the image. The commands you want to execute later to start the application will look for files (for example, in our case a python file) in this directory. Thus, the following part of the Dockerfile creates a directory and defines this as a working directory:

 RUN mkdir -p /usr/src/app WORKDIR /usr/src/app 

As a next step, you copy the contents of the folder in which the Dockerfile is stored in the image. In our example, the hello.py file is copied to the directory that we created in the previous step.

 COPY . /usr/src/app 

Finally, the following line executes the command "python hello.py" in your image:

 CMD [ "python", "hello.py" ] 

The full Docker file is as follows:

 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 create an image by entering it into the terminal:

 $ docker build -t hello . 

It will take some time. Then check if the β€œhello” image was successfully created, as we called it on the last line:

 $ docker images 

Launch the image:

 docker run hello 

The output cry will be "hello" in the terminal.

This is the first launch. When you use Docker for web applications, you need to configure ports, etc.

+2
source

If it's a multi-tier Java or python-based application, you can use solutions like goPaddle ( http://gopaddle.io ) to convert an existing application to docker drawings.

0
source

First, you need to choose the platform to run your application (for example, Ubuntu). Then install all the system tools / libraries needed to run your application. This can be achieved using the Dockerfile. Then click Dockerfile and the app on git or Bitbucket. Later, you can automatically build in a docking hub from github or Bitbucket. The later part of this lesson here contains more. If you know the basics, just move them forward until 50:00.

0
source

Source: https://habr.com/ru/post/1201092/


All Articles