To try out Docker on Local PC either we can get the Docker installed from the docker official website, or have it installed under a Linux VM to simulate a more Enterprise type setup on your Local PC.
- Win 10
- VirtualBox Installed
- Linux VM ubuntu 2004 configured in the VirtualBox.
1 – Install Docker
sudo apt install docker.io
2 – Install Docker dependencies
sudo snap install docker
3 – Thats it we are done here & you are good to explore docker now on your VM
sudo docker --version
Checking All docker packages & which are available in the repo & which are installed on our VM
Create & run an apache Hello world image in Docker
#In Current Dir create the HTML static files which you will push in Apache Webserver's htdocs mkdir public_html ; cd public_html ; vi HelloWorld.html #Put any content you wish in this file, save it with :wq in vim command mode. #Now go back to original directory & create Dockerfile: cd .. ; vi Dockerfile #copy & paste below 2 lines in Dockerfile. FROM httpd:2.4 COPY ./public_html/ /usr/local/apache2/htdocs #Now run below command to create the docker image sudo docker build -t my-apache2 .
So till now the image is created, now we need to run it inside a container, in that container apache server will be running on Port 80 & will be accessible to us on port 8080 externally due to mapping , you can map it to any port of your choice.
sudo docker run -dit --name apacheVB -p 8080:80 my-apache2 #-dit means , Detached(so that it runs in the background), Interactive (You can switch to it & run commands) T(with a TTY So you can see input & output # -p = Here we expose port 8080 externally which you can access from browser, it is mapped to port 80 which is apache port & running inside the container
#Check the container process details : sudo docker ps
Now test the webpage which is hosted in the apache, Open below URL
So today, we have setup Docker in Ubuntu 2004 on Virtualbox running on Windows 10.
Let us know if you faced any issues or errors while trying same.