Building Container Images Using Dockerfiles

samiullahsaleem

Sami Ullah Saleem

Posted on August 16, 2023

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

💖 💪 🙅 🚩
samiullahsaleem
Sami Ullah Saleem

Posted on August 16, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Docker
docker Docker

November 27, 2024

Containerization and Docker
undefined Containerization and Docker

November 27, 2024