This post describes how to run Apache on Atomic host. I am using Fedora atomic host.
Boot up an atomic instance (Fedora preferred).
To test the Apache container, just run
atomic run docker.io/fedora/apache
Make sure you are using
After the container has started successfully, Now do
This will display
Now If you want to build your own image copy the source https://github.com/fedora-cloud/Fedora-Dockerfiles/tree/master/apache down to your host.
Then Edit the Dockerfile and make your changes.
Now Build the image:
# docker build --rm -t /httpd .
After the build is successful, Run the container:
# docker run -d -p 80:80 /httpd #To assign port 80 of your host that maps to port 80 on the container
# docker run -d -p 80 /httpd #To assign random port that maps to port 80 on the container
If you do curl http://localhost you will see the required output.
Docker is an open source tool that helps us to develop, ship and run applications. Each and every application needs a Dockerfile. Instructions are written over Dockerfile in a layered/step-by-step structure to run the application. The Dockerfile is then built to create Docker image. We can then push the image either to Docker Hub or keep it in our Workstation. Finally to run the application we have to run container from the image which can be treated as a concept like an instance of the image since we can have more than one container of a single image. If the Docker image is not in our local Workstation we first have to pull the image from Docker hub and then run container from it. But when we need to make changes in Dockerfile(as needed to make changes in application) we have to build a new Docker image again from it. Or we can make change in the container we are running and commit it but that doesn’t reflect the Dockerfile which contains all the instructions to run an application say it for development or production purpose. Also building Docker image locally from Dockerfile makes us doing things like build, push and all manually. Automating build of Docker image from Dockerfile that is either on Github or Bitbucket is the only solution for this 🙂 .
In Short: We first create Dockerfile and then push it to Github or Bitbucket. After authenticating Github account with Dockerhub we choose repository on Dockerhub from Github that contains the Dockerfile. After that the Dockerfile triggers build which in result creates Docker image getting ready to pull.
I will share an example of making a CentOS image having Apache httpd server pre-installed.
First we need to create a Dockerfile which can be viewed here.
MAINTAINER trishnag <firstname.lastname@example.org>
RUN yum -y update; yum clean all
RUN yum -y install httpd
RUN echo "This is our new Apache Test Site" >> /var/www/html/index.html
RUN echo "/sbin/service httpd start" >> /root/.bashrc
Then push the Dockerfile to Github. I have created a repository named CentOS6-Apache and pushed the Dockerfile to it. The repository can be found here.
After doing so
- Go to DockerHub and Settings —> Linked Account —> Link your Github account.
- Create —> Create Automated Build —> Create Auto-build Github.
- Select the repository that contains Dockerfile of your application.
- Create followed by the Automating build process.
After the image is built successfully you will be able to see
Success in Build Details which indicates that the image is successfully built. The Image is now live on docker hub https://hub.docker.com/r/trishnag/centos6-apache.
Now we have to test the image to make sure whether Apache httpd server is actually pre-installed or not.
docker pull trishnag/centos6-apache #Pull the image from Dockerhub
docker run -t -i -d trishnag/centos-apache /bin/bash #Run the container as daemon
docker ps #Get the name of the container
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8bcd1199bb8f trishnag/centos6-apache "/bin/bash" 2 minutes ago Up 2 minutes 80/tcp jovial_cray
docker logs jovial_cray #To see What is happening on bash of container.Gives httpd status
docker inspect jovial_cray | grep IPAddress #Shows the IPAddress
curl 172.17.0.1 #curl the IPAddress we got
This is our new Apache Test Site
We just have got the text that we echoed out to index.html. Hence we can finally come to conclusion that Apache httpd server has already been pre-installed in the image.
Now even if we commit changes to the Dockerfile on Github we really don’t have to worry about the image. The build process of Docker image starts automatically once any changes are committed to Dockerfile. When we pull the newly built image and run container we will be able to find those changes.
Automating build process really makes our life easier.