Javascript required
Skip to content Skip to sidebar Skip to footer

How to Upload Documents to New Innovations

https://thingsolver.com/wp-content/uploads/docker-cover.png

Why Docker?

Developing applications in our days requires much more writing code. There are and so many languages, frameworks, interfaces and tools to create one application which leads to large complication. And how tin someone deploy these environments in any machine? This is where Docker comes into play!

The approach of building an image is similar to edifice a virtual auto. First of all you need to determine upon the Os of the image. In windows, the user can select whether wanting to build a Linux or a Windows image. In this tutorial we will continue with building a Linux epitome.

In order to explicate further what an image/container is, we can imagine an prototype as a virtual box. The image contains every information and information that is needed for a specific application to run, regardless the OS that the container is operating.

''A Docker container is an open source software development platform. Its primary benefit is to package applications in containers, allowing them to be portable to any system running a Linux or Windows operating system (Os). A Windows machine tin run Linux containers past using a virtual machine (VM)''.

Proof of Concept

In this scope we have implemented an awarding that has a trained Mask RCNN model in order to characterize metal material powders that are used for Additive Manufacturing. Our implementation uses the Matterport Mask RCNN implementation [https://github.com/matterport/Mask_RCNN/wiki] along with several changes to match our dataset and the scope of this trouble.

Step 1: Structure

First of all, the user must create a fine structure for the project. The project skeleton should include the proper noun of the project along with all the data, lawmaking, requirements that are going to exist used to build the Docker file.

a) The requirements.txt is crucial that is in the correct format. In order to verify this, endeavor and create a Python Virtual environment and run the following command.

(We utilize the anaconda prompt to test the following procedure).

            $ (base) conda create --name test_environment python==3.7
$ (base) conda activate test_environment
#Copy the requirements.txt in the directory you are currently working
$ (test_environment)pip install -r requirements.txt

Notation: If y'all don't have a requirements.txt you can type in the directory of your source code:

            $ pip freeze > requirements.txt          

This will write all the requirements that are installed in your environment in the requirements.txt in the directory you are located. Follow the above guidelines to install all dependencies.

If this step runs smoothly, nosotros tin can move on to creating the Dockerfile. Docker volition search for a file named Dockerfile within the directory yous volition build the prototype.

Step 2: Create the Dockerfile

Create a file named Dockerfile (txt merely without .txt in the end or else it will not work!!!)

You tin can proper noun your dockerfile at your own gustatory modality…

For more info follow the official Docker documentation here and search for the — file argument here

The following is the Dockerfile:

            # FROM selects the image to find on docker hub and selects the tag specified. Hither we select the              python              image and the 3.7 version (as tag)              
FROM python:3.7 # or else the Python version you want
# this is the piece of work directory WORKDIR /user/src/app RUN apt-get update RUN apt install -y libgl1-mesa-glx # Copy the requirements.txt COPY ./requirements.txt /user/src/app/requirements.txt # Run the pip - install RUN pip install -r requirements.txt # Betrayal the port that the container will communicate Betrayal 5000 # Copy source code and everything COPY . /user/src/app CMD [ "python", "main.py" ]

For the Dockerfile to build smoothly without errors, there are some rules that need to exist followed. Dockerfile is in full general expecting a command name and a set of arguments. These are reserved keywords (such as CMD, FROM).

Permit's get through the Dockefile arguments…

  • The WORKDIR specifies the working directory inside the container. This is the location where the source lawmaking, etc will be placed.
  • The adjacent step is to RUN the updates on your linux container. As well we run a command that installs some dependencies concerning the server that we volition be using.
  • Re-create command will copy the requirements.txt from our electric current (windows) directory in the WORKDIR (usr/src/app/). The next footstep is to RUN the pip install control which will install all the dependencies found within the requirements.txt.
  • Expose is a very crucial command in the Docker file. As the discussion is based on containers, the question comes on how it is possible to communicate with this container. In order for the container to communicate with the "outer world" it is crucial that we ascertain which PORT is left open. Past exposing a port we volition exist able to interact with the running container.
  • COPY will copy all files and directories from our local directory to the WORKDIR, or else our container will not include all the files we want.
  • CMD (Command Line) will execute the command specified in the brackets (ex. hither python master.py)

This is it! Y'all have created your first Docker file.

Stride three: Build your image

Now let'south become into details on how to build the image!

Locate yourself within the directory you take created the docker file.

In powershell or CMD (Windows) or by typing the following on any command line (linux or MacOS):

            docker build --tag <tag_you_want>:<tag> .          

If <tag> is ommited, then latest will be practical as default.

Annotation: if you lot get the following mistake 'failed to solve with frontend dockerfile.v0: failed to create LLB definition: no build stage in current context', then set the following ii variables to to disable docker buildkit and to employ the Compose python client for edifice images instead of the native docker CLI (using your control line):

Set up DOCKER_BUILDKIT=0
Ready COMPOSE_DOCKER_CLI_BUILD=0

(IN LINUX use export instead of SET)

Likewise keep in mind that Docker keeps a local enshroud retentiveness for epitome it is trying to build. By using the argument –no-cache while building, Docker will not runway the existing build if it fails and therefore volition start from scratch when rebuilding.

Docker volition build the paradigm with the name <tag_you_want> and the "." Specifies that the Dockerfile is establish within the same directory you are running this command.

As soon every bit the docker builds your image, yous can verify the being of your epitome past typing:

            # Display all the images in your motorcar
docker images

Step four: Run the container

To run the container there are two possibilities:

  1. Run the container using the Docker Desktop

a. Start Docker Desktop.

b. Find the Container/Image you lot want to start.

c. Brand sure to select the Port you would similar your local application to communicate with the exposed 5000 port via TCP (default) on the running Container.

Docker will prompt you to select whatever "Optional Changes"

d. Click Run aaaand magic! You app is working!

Verify that your container is running:

For our application, we run the app on the container localhost on port 8000 . So, if we blazon: http://localhost:8000/ on a spider web platform (Chrome etc) we can see this:

This is our forepart page runing on Flask

ii. Run the container from the control line

If y'all are using linux or if you want to run your container while using the command line follow these instructions…

            docker run -p 8000:5000 mask_rcnn_app_dfile          

-p specifies the ports that the docker file will run. The 8000 in the 1st position specifies the local port while the 5000 in the 2nd position is the container port. In this mode the container can communicate with the local machine.

Application name: mask_rcnn_app_dfile or the name you want to add.

If we type: http://localhost:8000/ on a web platform (Chrome etc), Once once more the user will encounter the same results.

The user can also interact with the container using the CLI module institute next to the running instance. By typing ls the user can see the files within the container or check out the running processes past typing ps -ef.

Click on the CLI to collaborate with your container

Push to the Docker Hub Repository

To push the epitome repo to Docker Hub in 2 dissimilar ways (using command line, using docker desktop):

  • If you lot don't have a Docker account, caput to https://hub.docker.com to create i (your docker account will be the docker username you will select during the sign upwardly).
  • Annotation: You demand to tag the image proper noun equally shown using the CMD:
                          $ docker image tag <your_image_name> <user_name>/<your_image_name>                      

Note: Only and only if the paradigm proper name matches the following convention: <user_name>/<your_image_name> you will be able to button in the Docker Hub repository!

i. Using the command line:

                          $ docker login                        // fill up in your username and countersign
// If done correctly volition get message:
Login succeeded
$ docker prototype tag <image_name> <new_image_name> The <new_image_name> must exist the same with the repo you are going to upload.
For instance:
$ docker image tag my_app_test user_name/my_app_test This will create a new image in your local docker repo that volition exist named accordingly or else docker will not upload the image! $ docker image push user_name/my_app_test

2. Using the Docker Desktop (Windows only)

Open the docker Desktop application

Create an business relationship, if yous are a new user here: https://hub.docker.com/signup

Go back to Docker Desktop and click Log in at the elevation correct of your screen.

Click on Push to Hub to push the image to Docker Hub repository

Push to Hub!

chaffeythounater44.blogspot.com

Source: https://medium.com/innovation-res/how-to-build-run-and-upload-your-docker-image-on-docker-hub-6049a2601d19