Docker Tutorial Part-1
Docker is Container management service used by the developers to develop applications and put that in the container created by docker, so that they can easily deployed anywhere.
Companies can ask about Docker basics during the interview as it is widely used by developers now a days. So it is good idea to have basics ready for the interview.
First, you need to download Docker and install. Once you install, you can see the Docker terminal, open the terminal and write the first command as
docker run hello-world
This command will download the hello-world image if it is already not present and then run hello-world as container.
If the command is successful then you will see
Hello from Docker!
This message shows that your installation appears to be working correctly.
You can also look for Docker images available on your system as
docker images
hello-world
How to Build the Docker images?
To Build the docker images you need to create Docker file named as Dockerfile and build it.
Sample Docker file:
FROM ubuntu
MAINTAINER 2p4int@gmail.com
RUN apt-get update
RUN apt-get install -y python python-pip wget
ADD test.py /home/test/test.py
CMD ["echo", "created image"]
This docker file starts from keyword FROM, which tells docker about the base image from which you want to create your image, so it takes from Ubuntu base image.
Next we RUN the dependencies and ADD out python file in the directory /home/test inside the docker container.
Now, keep the Dockerfile and test.py in the same folder and build the image by moving to the directory of folder and run the below command
docker build -t your-new-image-name .
(Don't forget the dot at the end)
This will create the docker image with your new image name on your system.
Now, you can check again all your images using docker images.
Once you created your docker image you can run it to create the container using the command
docker run -it --rm -p 8888:8888 your-new-image-name
Now this will create the container with some random name on your system which you can check using
docker container ls
We will discuss the DockerFile with all the commands and more usage of Docker container in our next blog posts.
Companies can ask about Docker basics during the interview as it is widely used by developers now a days. So it is good idea to have basics ready for the interview.
First, you need to download Docker and install. Once you install, you can see the Docker terminal, open the terminal and write the first command as
docker run hello-world
This command will download the hello-world image if it is already not present and then run hello-world as container.
If the command is successful then you will see
Hello from Docker!
This message shows that your installation appears to be working correctly.
You can also look for Docker images available on your system as
docker images
hello-world
How to Build the Docker images?
To Build the docker images you need to create Docker file named as Dockerfile and build it.
Sample Docker file:
FROM ubuntu
MAINTAINER 2p4int@gmail.com
RUN apt-get update
RUN apt-get install -y python python-pip wget
ADD test.py /home/test/test.py
CMD ["echo", "created image"]
This docker file starts from keyword FROM, which tells docker about the base image from which you want to create your image, so it takes from Ubuntu base image.
Next we RUN the dependencies and ADD out python file in the directory /home/test inside the docker container.
Now, keep the Dockerfile and test.py in the same folder and build the image by moving to the directory of folder and run the below command
docker build -t your-new-image-name .
(Don't forget the dot at the end)
This will create the docker image with your new image name on your system.
Now, you can check again all your images using docker images.
Once you created your docker image you can run it to create the container using the command
docker run -it --rm -p 8888:8888 your-new-image-name
Now this will create the container with some random name on your system which you can check using
docker container ls
We will discuss the DockerFile with all the commands and more usage of Docker container in our next blog posts.
Comments
Post a Comment