Step-by-Step Process or Creating and Using Dockerfile and Docker Compose File
Step-1: Launch EC2 Instance
- Login to AWS Console and launch EC2 Instance
Step 2: Install Docker
- Now install docker in our local machine by using following commands
sudo yum -y install docker
Step 3: Create Dockerfile
- Here is the dockerfile to build a Docker image
FROM amazonlinux:latest
RUN yum update -y
yum install -y git python3-pip
RUN git clone https://github.com/Sada-Siva-Reddy07/fish.git /fish
WORKDIR /fish
RUN pip3 install –no-cache-dir -r requirements.txt
EXPOSE 2000
CMD [“python”, “app.py”]
Step 4: Build the Docker Image
- Now run the below commands to build docker image
docker build -t <filename> .
Step 5: Run the Docker Container
- Now the docker container by using following commands
docker run -dt -p 8000:8000 <filename>
- Here docker images list by using docker ps.
- docker image was successfully build
Docker Compose vs. Dockerfile with Code Examples
Docker is an open-source platform that empowers developers to automate the deployment of applications inside lightweight, portable containers. Containers encapsulate an application and its conditions, ensuring consistency across various conditions, from advancement to production, the Dockerfile and the Docker Compose file are two essential Docker tools that make containerization easier.
A set of instructions for making a Docker image can be found in a text file called a Dockerfile. Each instruction in a Dockerfile creates a layer in the image, ensuring the consistency and reproducibility of the application and its dependencies.
Then again, a Docker Compose file is utilized to define and run multi-container Docker applications. Docker Compose makes it simpler to orchestrate complex applications by allowing users to set up and manage multiple containers, networks, and volumes through the use of a straightforward YAML configuration file
Understanding how to make and utilize Dockerfiles and Docker compose files is essential for anybody seeking to influence Docker for proficient application deployment and the executives. This guide will go over the fundamentals of these tools, show you how to make and use them, and give real-world examples to show how to do so.