Docker Basic Commands - Part 02
Megha kadur
Senior Software Engineer | Azure Certified | 22K + LinkedIn | GitOps certified | DevOps Speaker | 9K + subscribers on Youtube | Helping people break into DevOps
Steps to install Docker:
Below is the link for docker installation, that is provided by Docker, we have clear documentation available for installing docker. This link will direct you to official docker documents.
Once docker is installed check the version of docker?
Let’s familiarize our self with few basic docker commands:-
?Gives you the list of active containers on your machine
In the output we can see it displays few details about the container
CONTAINER ID: Each and every container will be assigned with a unique ID
IMAGE: Every Image has an attached tag
COMMAND: Each and every image will be assigned with a unique ID
CREATED: shows the detail when it was created
STATUS: Shows the detail whether the container is active or not
PORTS: Exposed port
NAMES:? Random name is assigned by docker for container created
Gives you the full list of containers including the one's which are stopped or crashed
Gives you the list of images present in the system
?It will create a container using the image name
Here arguments -itd means
I – Interactive
T – Connected to terminal
D – Detached Mode
We can run? the container as detached mode (-itd) or root mode (-td)as per the requirement.
?To stop the container
领英推荐
To remove a container
To remove a docker image
Get access to shell of container?
With this command we can run our required code within the container.
Volume acts as data warehouse, or data storage attached externally to container.
Lets say for example in data directory (data) we have data1 and data2 as file that are part of the data associated for our application to work with.?
but we do not want these data to be really stored within container, instead of that we want it be mounted, so the actual read and write will happen within data1 and data2 it will look like it’s a part of container. So these mounted data are called as Volumes.
Now that we have basic idea about creating, deleting and starting a container, further will see how to create your own image.
On our server machine we need to install Apache2 by running below mentioned commands:
sudo apt-get update
sudo apt-get install apache2
Creating a Dockerfiles:
Create a directory as sample-code within that create a? Dockerfile and index.html file
Every dockerfile starts with FROM command which tells? from where is the base image coming from , here? we are telling to use httpd as our base image, and then we want to add a file? index.html, which will act as our source and our destination will be ?/usr/local/apache2/htdocs/index.html, when we run this file docker will create a temporary container and it will create an image out of it once the image is created we can use this image to create a container out of it.?
docker build? . -t first-image: this command will build an image where first-mage is the name of image
docker run -itd? --name first-container -p 8090:80 first-image: this command will build the container where first-container is name of container mapped to port 80
we can see the output : https://server_IP:port?
Conclusion:
We came across various terms and parameters that are used in docker to containerize an application, Docker containers are better that virtual machines which ensure that our application runs without an error, it makes the complicated process into simple way of containerizing? our application.