Docker for DevOps Engineers.

Docker for DevOps Engineers.

Introduction:

Docker is an open-source platform that allows you to automate the deployment and management of applications within lightweight, isolated containers. It provides a consistent environment for software development, testing, and deployment across different systems. With Docker, you can package your application and its dependencies into a container, ensuring that it runs reliably and consistently on any infrastructure. It simplifies the process of building, distributing, and running applications, making it easier to achieve scalability and portability in your software projects.

To know what actually docker is, click here to understand the docker with an analogy.

Today we will deep dive into the installation of docker ,install MySQL & many useful command of docker.

✔️Install docker:

To install docker you have to run this command

sudo apt install docker.io

Now your system has a docker installed.

Once you installed Docker you have to create an account on Docker Hub.

To create an account on Docker Hub, you can follow these steps:

  1. Open your web browser and go to the Docker Hub website at hub.docker.com.

  2. Click on the "Sign Up" button in the top-right corner of the page.

  3. You have two options to create your account: you can sign up with your Docker ID, or you can sign up with your GitHub account. Choose the method that you prefer.

    If you signed up with your Docker ID, Docker Hub will send you a confirmation email. Check your email inbox and click on the confirmation link to verify your email address. If you don't see the email, make sure to check your spam folder.

  4. After verifying your email address, you will be redirected to the Docker Hub website. You can now log in to your newly created account using your email address and password.

  5. You are successfully logged into the docker hub.

Now come back to your terminal

And run the following command to login into the docker

sudo docker login

give the credentials(user id &password) to log in

Now everything is completely set up, come into tasks

✔️Tasks :

  1. Use the docker run command to start a new container and interact with it through the command line. [Hint: docker run hello-world]

    step 1: Check the users present in your system, just type sudo cat /etc/passwd
    step 2: Now create a group and add your current user to the new group by typing this command

     sudo usermod -a -G docker $/USER
    

    step 3: Now Restart your system using sudo reboot

    step 4: Now type

     docker ps
    

    Now you see the output as:

    ✔️Pull MySQL:

    step 1: write docker pull mysql to pull mysql

    step 2: Now see the image using docker images

step 3:To create a conatiner of it

docker run -p 3306:3306 -e MYSQL_ROOT_PASSWORD= -d mysql:latest

 # 3306 -> Port number for MySQL
 # -e -> Creating a new environment variable
 # MYSQL_ROOT_PASSWORD -> setting up the password for server
 # -d -> detached mode, it will execute in background no logs will showed
 # mysql:latest -> image_name:tag_associated_with_version

step 4:To execute the docker container:

docker exec -it <container_id> bash

step 5:Once the bash script started we can log in to the MySQL server using the password

 mysql -u root -p
 # root is the default user name
 # Enter the password to login successfully

Finally, MySQL running in your os.🌟

🔎 Use the docker inspect command to view detailed information about a container or image.
Type docker ps to get the container id

The syntax for the container: docker inspect <container_id>

🔎 Use the docker port command to list the port mappings for a container.

syntax: docker port <container_id>

🔎 Use the docker stats command to view resource usage statistics for one or more containers.

syntax: docker stats <container_id>

🔎 Use the docker top command to view the processes running inside a container.

syntax: docker top <container_id>

🔎 Use the docker save command to save an image to a tar archive.

syntax : docker save -o <file_name.tar> <image_name>
I just created a docker directory to save that file

The below command saves a Docker image named "mysql" as a tar archive file named "mysql.tar" in the current directory.

🔎 Use the docker load command to load an image from a tar archive.

syntax: docker load -i <file_name.tar>

For another docker blog.

Follow me on LinkedIn to see interesting posts like this : )

linkedin.com/in/prabir-kumar-mahatha-6a0025..

visit my git hub profile: github.com/PrabirKumarMahatha