DevOps, Day - 18

DevOps, Day - 18

Docker for DevOps Engineers

Docker compose

  • Docker Compose is a tool for managing complex multi-container Docker applications.

  • You define your application's different services and their settings in a simple YAML file.

  • You can start, stop, and restart your application and its services with a single command, and easily scale it up or down as needed.

  • Docker Compose can work with other orchestration tools, such as Docker Swarm, to help you manage and deploy your application at scale.

  • Using Docker Compose can make it easier to collaborate and share your application with others, and can help ensure a consistent and reproducible environment for development and testing.

  • Simplifies container management: Docker Compose makes it easy to manage multiple containers as a single application.

  • Enables easy deployment: You can easily deploy your application to any environment using Docker Compose.

  • Facilitates version control: Docker Compose files can be version-controlled using tools like Git.

  • Provides environment consistency: Docker Compose ensures that all containers in an application are running on the same version of the software.

  • Offers scalability: Docker Compose makes it easy to scale container-based applications horizontally.

How to run docker commands without using SUDO?

  • step 1: use sudo useradd $USER command to add the user

  • step 2: check whether the user is added

    we can see the user is added successfully.

  • step 3: use sudo usermod -a -G group_name user_name command
    [Add the new user to the "docker" group to permit them to run Docker commands]

    step 4: After executing this command, don't forget to reboot the system.

    Now, re-connect with the aws instance and just execute the commands even without using sudo :)

    Here is the proof of not using sudo for any command.

Tasks:

  1. 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.

    step 1: pull the existing image by using the command docker pull username/image:tag as shown below.

    step 2: run the container.

    step 3: check the running containers using docker ps command

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

    type docker images to get the image_id

    use docker inspect <image_id>

    OR

    docker inspect username/image_name:tag
    Example: docker inspect vrishnishreevb/mynginx:1

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

    use the command docker logs container_id

  4. Use the docker stop and docker start commands to stop & start the container.

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

    To remove the container...
    step 1: First, stop the container using the docker stop <container_id>command.
    step 2: Then, remove the container docker rm <container_id> command as shown below.

Let's learn more about this in upcoming blogs : )

Thank you so much for reading.

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

Linkedin

Β