DevOps(Day-18) : Docker deep dive

DevOps(Day-18) : Docker deep dive

SPEED1X

TABLE OF CONTENTS

Docker Compose

It is a multi-container service that is used to spin up many containers at a time. With docker-compose, we can start, stop and rebuild services, can check the status of the services, and can run an On-Off command.

To write a docker-compose file we use YAML language.

YAML

YAML stands for Yet Another Markup Language.

It is a human-readable language used for writing configuration files.

It's recommended that configuration files be written in YAML rather than JSON, even though they can be used interchangeably in most cases because YAML has better readability and is more user-friendly.

YAML is used in DevOps tools like Ansible and Kubernetes.

Task-1

Learn how to use the docker-compose.yml file, to set up the environment, configure the services and links between different containers, and also to use environment variables in the docker-compose.yml file.

  1. Install Docker compose on the system.

    $ apt install docker-compose

  2. Pull the source code from the GitHub repo and create the image.

    $ docker build . -t django-notes-app

  3. Create the docker-compose.yml file and include the containers you want to run with its images.

    • 3.3 is the version of the docker-compose.

    • Services contain the number of containers or applications the user wants to run.

    • Ports refer to the particular application being exposed to an external URL.

    • Environment passes the credentials or data to be passed to the container.

  4. Run the docker-compose.yaml file.

    $ sudo docker-compose up

  5. Now the containers are up and you can monitor the application through the web URL.

  6. After the task completion, you can use the below command to make the docker containers down.

    $ sudo docker-compose down

Task-2

  • Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine. Run the container as a non-root user (Hint- Use usermod command to give user permission to docker). Make sure you reboot instance after giving permission to user.

  • Use the below command to provide docker execute permission to non-admin user. You can check now all the docker commands can be executed without the prefix "sudo"

    $ sudo usermod -a -G docker $USER

  • Inspect the container's running processes and exposed ports using the docker inspect command.

    $ docker inspect <image_name>

  • Use the docker logs command to view the container's log output.

    $ docker logs <container_id>

  • Use the docker stop and docker start commands to stop and start the container.

    $ docker stop <container_id>

    $ docker start <container_id>

  • Use the docker rm command to remove the container when you're done.

    $ docker rm <container_id>

Thanks for reading my article. Have a nice day.

WRITTEN BY Biswaraj Sahoo --AWS Community Builder | DevOps Engineer | Docker | Linux | Jenkins | AWS | Git | Terraform | Docker | kubernetes

Empowering communities via open source and education. Connect with me over linktree: linktr.ee/biswaraj333