DevOps Tools: Docker

In this tutorial, I will show you how to create your first docker file

Background

Interested in containerization across any cloud platform? Choose Docker.

Docker is a containerization platform that provides easy way to containerize your applications. If you use Docker, you will build container images, run the images to create containers and also push these containers to container regestries such as DockerHub.

In other words, Docker implements containerization.

Common docker commands you should know:

  • docker run: runs a Docker container.
  • docker build: builds image from Dockerfile.
  • docker images: lists docker images on the host machine.

DevOps Project Outline

Your manager asked you to create an Ubuntu EC2 instance and install docker.

Prerequisite

  • Access to AWS account.
  • Install docker.
  • Access to dockerhub.com

Let’s have fun.

Step 1- Create EC2 instance

  • Log in to your AWS account
  • I have a tutorial on how to create EC2 instance. Read more.
  • I created an EC2 instance named docker-ubuntu.

Step 2- Connect EC2 instance via SSH connection

  • I’ve created a tutorial detailing the steps to SSH connect to EC2 through MobaXterm on your Windows laptop. Discover more about it .
  • Alternatively, you can explore another tutorial explaining how to connect to EC2 instances via SSH using Linux. Read on for more details .

Step 3- Install docker in your EC2 instance

  • After connecting to your EC2, verify if the connection was successful.
  • Now, install docker by typing sudo apt install docker.io -y
  • Verify if docker is running:
  • As you can see below, docker is running.

Step 4- Add user to docker group

  • Now, try to run docker using docker run hello-world.
  • If you encounter an error or receive a ‘permission denied’ message, it’s likely because Docker always operates with root privileges.
  • Add ubuntu user to docker group and type the command below.
  • Log out and log back in to your EC2.
  • Now, type docker run hello-world. Docker is running.

Your Docker user profile isn’t activated automatically; you’ll need to create it manually.

Step  5- Create your first docker file

  • Clone this repo from GitHub. Click here for the url.
  • Locate the docker file. Open the file.

Cheat sheet: You can run this docker file or create another one.

  • Login to Docker.com using your username (Djcloudguru) and password (K******). To do so, enter docker login in the terminal.

5- Run your First Docker Image

  • Remember we are in the EC2 instance still. Locate docker file and execute this command docker build -t djcloudguru/my-first-docker-image:latest . (do not forget to add the . at the end of the command)
  • The result is as follows.

Remember the main purpose of this tutorial is to run application.

  • Execute the command below. You’ll get Hello world as output. Your application is running.

Step 6- Run your First Docker Container

  • Enter docker login in the terminal to verify if you are still logged in.
  • It’s a successful login.
  • Now, enter this command and share the image.
  • It’s a successful push.
  • After this image is pushed. Login into your docker hub and look it up.
  • This docker image can be share to everyone now.

Voila! You’ve created a docker file, run a docker image, and push a docker container.

Leave a Reply

Your email address will not be published. Required fields are marked *