Example: Install docker on AWS or Docker itself and create an image and open the container. In the container install the apache server with the port number and show its web page. And make a Docker file and write an HTML file and show it on web page.?
Step: 1 To see the Docker version
The command is sudo docker –version
Here is the docker new version which we are working on it.
Step: 2 To create the image
The command is sudo docker pull <image name>
This command is starting pulling the image which images already exist in Docker Hub.
Here I pulled two images from Docker Hub one is ubuntu and another one is MySQL
We can see two images are downloaded successfully.
Step: 3 To see the images.
The command is sudo docker images (By this command we can see the images)
Here it shows my images. So, we successfully created images. With image ID, size, and created time.
Step:4 Now run any one of the images to create the container.
Command is sudo docker run -it -d <image id>
Here we created two containers of two images.
Step: 5 To see whether the container is working or not.
The command is sudo docker ps (This command shows the working containers).
Here we can see the two containers with container id.
Step: 6 To see all the containers.
The command is sudo docker ps -a (This command shows all the containers).
Step: 7 To open the containers to do several changes like install any type of server.
Command is sudo docker exec -it <container id> bash
Now we are at the root.
Step: 8 Update the container.
The command is apt-get update
Successfully updated the container now we can do any changes.
Step:9 Now let’s install the apache server in the container.
The command is apt-get install apache2
It started installing the apache server.
Apache server is successfully installed here.
Step: 10 To see the status of the server.
The command is service apache2 status
It says the apache server is not running. So, we have to start the server.
Step: 11 To start the server
The command is service apache2 start
See now the apache server is running over the container. Exit from the container for that write exit and press the enter button. So, we get back to ubuntu.
Step: 12 Now save the changes in the container.
Command is sudo docker commit <container id> <new name>
We successfully saved the changes.
In the above command, we gave
Step: 13 Let’s see whether a new image is created or not.
Command sudo docker images.
See I gave the new name DevOps/apache in the command.
In the images, DevOps/apache images are created. And observe one thing in the above images list ubuntu is of 72.9Mb but the image DevOps/apache is 213Mb. Because there is an apache server in it.
Step: 14 Let’s run the image DevOps/apache.
Command is sudo docker run -it -d <imageid>
DevOps/apache image is working.
Step: 15 sudo docker ps.
Here we can see the DevOps/apache container is also working.
Step: 16 Let’s open the apache server on port number 82:80. Because the apache server is opened only on port number 80.
Command is sudo docker run -it -p 82:80 -d devops/apache
Step: 17 Let’s see the apache server on the web-page.
For that copy the instance IP address. Here my IP address is 54.237.73.251
Paste the IP address: port number on the web-page.
54.237.73.251:80
Step: 18 Let’s create a docker file.
Make a directory by the name of the docker file. I gave the file name docker file you can give any name.
Command mkdir docker file
mkdir command is used to create the director.
To open the directory.
Command cd docker file
cd command is used to open the file.
Open nano editor to write the docker file.
Command nano dockerfile
Step: 19
Save and exit from the editor.
Step: 20 Write a HTML file.
Open nano 1.html
Save and exit the nano editor.
Step: 21 Let’s see the HTML file on the web-page.
For that copy the instance IP address. Here my IP address is 54.237.73.251
Paste the IP address: port number/HTML file by which you are saved. I saved it as 1.html so paste
54.237.73.251:80/1.html on the web-page.
We have successfully created an HTML page on the web.