Deploying BadgeYaY with Docker on Docker Cloud
We already have a Dockerfile present in the repository but there is problem in many lines of code.I studied about Docker and learned how It is deployed and I am now going to explain how I deployed BadgeYaY on Docker Cloud.
To make deploying of Badgeyay easier we are now supporting Docker based installation.
Before we start to deploy, let’s have a quick brief about what is docker and how it works ?
What is Docker ?
Docker is an open-source technology that allows you create, deploy, and run applications using containers. Docker allows you deploy technologies with many underlying components that must be installed and configured in a single, containerized instance.Docker makes it easier to create and deploy applications in an isolated environment.
Now, let’s start with how to deploy on docker cloud:
Step 1 – Installing Docker
Get the latest version of docker. See the offical site for installation info for your platform.
Step 2 – Create Dockerfile
With Docker, we can just grab a portable Python runtime as an image, no installation necessary. Then, our build can include the base Python image right alongside our app code, ensuring that our app, its dependencies, and the runtime, all travel together.
These portable images are defined by something called a Dockerfile.
In DockerFile, there are all the commands a user could call on the command line to assemble an image. Here’s is the Dockerfile of BadgeYaY.
# The FROM instruction initializes a new build stage and sets the Base Image for subsequent instructions.
FROM python:3.6
# We copy just the requirements.txt first to leverage Docker cache
COPY ./app/requirements.txt /app/
# The WORKDIR instruction sets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it in the Dockerfile.
WORKDIR /app
# The RUN instruction will execute any commands in a new layer on top of the current image and commit the results.
RUN pip install -r requirements.txt
# The COPY instruction copies new files.
COPY . /app
# An ENTRYPOINT allows you to configure a container that will run as an executable.
ENTRYPOINT [ "python" ]
# The main purpose of a CMD is to provide defaults for an executing container.
CMD [ "main.py" ]
Step 3 – Build New Docker Image
sudo docker build -t badgeyay:latest .
When the command completed successfully, we can check the new image with the docker command below:
sudo docker images
Step 4 – Run the app
Let’s run the app in the background, in detached mode:
sudo docker run -d -p 5000:5000 badgeyay
We get the long container ID for our app and then are kicked back to our terminal.Our container is running in the background.Now use docker container stop to end the process, using the CONTAINER ID, like so :
docker container stop 1fa4ab2cf395
Step 5 – Publish the app.
Log in to the Docker public registry on your local machine.
docker login
Upload your tagged image to the repository:
docker push username/repository:tag
From now on, we can use docker run and run our app on any machine. No matter where docker run executes, it pulls your image, along with Python and all the dependencies from requirements.txt, and runs your code. It all travels together in a neat little package, and the host machine doesn’t have to install anything but Docker to run it.
Docker Cloud
Docker Cloud provides a hosted registry service with build and testing facilities for Dockerized application images; tools to help you set up and manage host infrastructure; and application lifecycle features to automate deploying (and redeploying) services created from images.
In BadgeYaY, we also have a Deploy button button which directly deploys on Docker cloud with a single click .
The related PR of this work is https://github.com/fossasia/badgeyay/pull/401 .
You must be logged in to post a comment.