This content originally appeared on DEV Community and was authored by Hyelngtil Isaac
Introducing Today’s Project!
What is Docker?
Docker is a tool for building and running self-contained environments that package your app and its dependencies. I used Docker to create a custom container image that served a webpage, tested locally, and deployed it to AWS Elastic Beanstalk live.
One thing I didn’t expect.
One thing I didn’t expect in this project was that AWS Elastic Beanstalk would automatically create an S3 bucket and upload my zipped Docker project file to it. That behind-the-scenes setup made deployment smoother than I anticipated.
It took me about 90 minutes to complete the project, from installing Docker to deploying the app with Elastic Beanstalk.
Understanding Containers and Docker
Containers
Containers are packages that include an app and all its dependencies. They are useful because they ensure the app runs consistently anywhere.
A container image is a file that bundles an app with everything it needs to run like code, libraries, and settings so it behaves the same on any system.
Docker
Docker is a tool for creating, managing containers, and packages that hold everything an app needs to run. Docker Desktop is its user-friendly interface for local use.
The Docker daemon is the background service that builds, runs, and manages
containers, powering Docker commands and enabling app deployment
Running an Nginx Image
Nginx is a fast, lightweight web server used to serve web pages. In this project, it’s the container image that helps you test Docker by instantly loading a webpage.
The command I ran to start a new container was ‘docker run -d -p 80:80 nginx’. It launched an Nginx container in the background and mapped port 80 so I could view the webpage locally’
Creating a Custom Image
The Dockerfile is a text file with instructions to build a container image, like replacing Nginxʼs default page with your own and exposing port 80.
My Dockerfile tells Docker three things: use the official Nginx image, copy in my custom webpage to replace the default, and expose port 80 to serve it online.
The command I used to build a custom image with my Dockerfile was ‘docker build -t my-web-app .’ The ‘.’ at the end of the command means Docker uses the current folder where the Dockerfile and ‘index.html’ live to build the image.
Running My Custom Image
There was an error when I ran my custom image because another container was already using port 80. I resolved this by stopping the active container in Docker Desktop and restarting mine.
In this example, the container image is the blueprint that defines what goes into the container, like the Nginx base and my custom webpage. The container is the running instance created from that image, serving my site locally.
Elastic Beanstalk
Elastic Beanstalk is an AWS service that helps you deploy containerized apps to the cloud easily, handling servers, scaling, and app health for you.
Deploying my custom image with Elastic Beanstalk took me just a few minutes 10 – 15, AWS handled setup, so my containerized app went live fast.
In the next project, I’m going to demonstrate how to ‘Deploy an App Across Accounts.’
This content originally appeared on DEV Community and was authored by Hyelngtil Isaac