DEV Community

Cover image for Building Container Images Using Dockerfiles
Sami Ullah Saleem for AWS Community Builders

Posted on

1

Building Container Images Using Dockerfiles

1- Create Dockerfile

~ vi Dockerfile
Enter fullscreen mode Exit fullscreen mode
FROM httpd:2.4
RUN apt update -y && apt autoremove
Enter fullscreen mode Exit fullscreen mode
  • Dockerfile always start from FROM keyword and after it we tell the image name like we are telling here httpd of which we want to create our container.
  • RUN whatever we are going to write after RUN it will be run in our container.
~ docker build -t wigetfactory .
Enter fullscreen mode Exit fullscreen mode
  • Here you can see that we are creating our image from our Dockerfile and giving it a name which is wigetfactory

2- Let's update our Dockerfile and put our website content in it.

FROM httpd:2.4
RUN apt update -y && apt autoremove
rm -f /usr/local/apache2/htdocs/
WORKDIR /usr/local/apache2/htdocs/
COPY ./web .
Enter fullscreen mode Exit fullscreen mode
  • Here you can see that I am changing my container work directory using *WORKDIR * command and then copy my website content from my host directory to the container location which is htdocs.

  • Let's run our Dockerfile again.

~ docker build -t widgetfactory:0.3 .
Enter fullscreen mode Exit fullscreen mode

Here will be the output of it

Dockerfile output

  • Now run container using the image.
docker  run --name weebproject -d -p 80:80 widgetfactory:0.3
Enter fullscreen mode Exit fullscreen mode

Follow me for more content

Image of Datadog

Create and maintain end-to-end frontend tests

Learn best practices on creating frontend tests, testing on-premise apps, integrating tests into your CI/CD pipeline, and using Datadog’s testing tunnel.

Download The Guide

Top comments (3)

Collapse
 
im6h profile image
Vu

How about if I do not use Dockerfile?

Collapse
 
samiullahsaleem profile image
Sami Ullah Saleem

Whatever you have written in the docker file. You have to do from your host terminal. But commands will be different.

Collapse
 
samiullahsaleem profile image
Sami Ullah Saleem

You can read my this article
dev.to/aws-builders/hosting-site-o...

Best Practices for Running  Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK cover image

Best Practices for Running Container WordPress on AWS (ECS, EFS, RDS, ELB) using CDK

This post discusses the process of migrating a growing WordPress eShop business to AWS using AWS CDK for an easily scalable, high availability architecture. The detailed structure encompasses several pillars: Compute, Storage, Database, Cache, CDN, DNS, Security, and Backup.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay