Skip to content

Instantly share code, notes, and snippets.

@atulkamble
Last active September 17, 2023 07:52
Show Gist options
  • Save atulkamble/4606e2a51a53f616e8c407b4021fdd85 to your computer and use it in GitHub Desktop.
Save atulkamble/4606e2a51a53f616e8c407b4021fdd85 to your computer and use it in GitHub Desktop.
docker1webapphelloworld

// To create a Docker image of a simple web application on EC2/Physical Machine

mkdir dockerfiles 
New-Item Dockerfile

OR

touch Dockerfile

Add following content to file

FROM ubuntu:18.04

#Install dependencies

RUN apt-get update && \
 apt-get -y install apache2

# Install apache and write hello world message

RUN echo 'Hello World!' > /var/www/html/index.html

# Configure apache

RUN echo '. /etc/apache2/envvars' > /root/run_apache.sh && \
 echo 'mkdir -p /var/run/apache2' >> /root/run_apache.sh && \
 echo 'mkdir -p /var/lock/apache2' >> /root/run_apache.sh && \ 
 echo '/usr/sbin/apache2 -D FOREGROUND' >> /root/run_apache.sh && \ 
 chmod 755 /root/run_apache.sh

EXPOSE 80

CMD /root/run_apache.sh

docker build -t hello-world .

sudo docker images

docker run -t -i -p 80:80 hello-world


http://localhost/.

docker scout quickview

Push Docker Image to Docker Hub

docker login 

docker tag hello-world:latest atuljkamble/hello-world

Then list images

docker images 

Check image with latest tag Push image to Docker Hub

docker push atuljkamble/hello-world
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment