Home » Docker Basics: Your First Container Step-by-Step Guide

Docker Basics: Your First Container Step-by-Step Guide

Docker Basic : Your First Container

Introduction

That’s where you begin if you’re just starting your journey into containers on AWS – not with ECS, not with EKS, but with Docker. Every container running on AWS (whether on ECS, EKS, or Fargate) starts as a Docker image. So today we put our hands on Docker itself: installing it, running our first container, building a custom image, and pushing it to Amazon ECR, AWS’s own container registry.
Let’s take it one step at a time

Prerequisites

  • An AWS account (free tier is enough)
  • An EC2 instance (Amazon Linux 2) or your local machine with Docker support
  • AWS CLI configured with your credentials

Step 1: Launch an EC2 instance and SSH

  • If you don’t know how to launch EC2 instances and how to access instances using SSH, you can go through this link: how to create EC2 instance

Step 2: Install Docker and Verify

  • On Amazon Linux EC2 instances, Docker isn’t installed by default, so we have to install docker and verify
Multi Copy Code Blocks
bash

sudo yum update -y
sudo yum install docker -y
sudo service docker start
sudo usermod -a -G docker ec2-user

    
  • After running the usermod command, log out and log back in so the group change takes effect; otherwise, you’ll have to prefix every Docker command with sudo.
  • Now Verify the installation
Multi Copy Code Blocks
bash

docker –version
sudo docker run hello-world
    
  • If everything is set up correctly, you’ll see a “Hello from Docker!” message. This confirms Docker can pull images and run containers successfully.

Step 2: Run Your First Real Container

  • Installing Docker is one thing; running something useful is another. Let’s spin up an Nginx web server.
Multi Copy Code Blocks
bash

docker run -d -p 8080:80 --name my-first-nginx nginx
docker ps
curl http://localhost:8080
    
  • You can also use EC2 public IP on your browser like https://ec2_public_ip:8080/
  • The -d option starts the container in detached mode (in the background), and -p 8080:80 maps port 80 in the container to port 8080 on your host. Running curl should return the HTML of the default Nginx welcome page.

Step 3: Build Your Own Custom Image

This is the real learning moment: building your own image instead of just using someone else’s.

  • Create a project folder and a simple HTML file
Multi Copy Code Blocks
bash

mkdir my-app && cd my-app
echo "<h1>Hello from my container, AWS Community Builder!</h1>" > index.html
    
  • Now create a Dockerfile
Multi Copy Code Blocks
bash

FROM nginx:alpine
COPY index.html /usr/share/nginx/html/index.html
EXPOSE 80
    
  • Build and run it
Multi Copy Code Blocks
bash

docker build -t my-first-app:v1 .
docker run -d -p 8081:80 --name my-app-container my-first-app:v1
curl http://localhost:8081
    

Now you should see your own custom message instead of the default Nginx page. That’s the basic idea behind containers: the image is a portable, immutable template, and every container you run from it acts the same way, anywhere.

Step 4: Practice Core Docker Command

  • Before moving to AWS-specific services, it is worth getting comfortable with the everyday Docker commands you’ll use constantly:
Multi Copy Code Blocks
bash

docker ps -a                          # list all containers, running or stopped
docker logs my-app-container           # view container logs
docker exec -it my-app-container sh    # open a shell inside the running container
docker stop my-app-container
docker start my-app-container
docker rm -f my-first-nginx            # remove a container
docker images                          # list all local images
    

Spend a few minutes with each of these; you will be relying on knowing how to inspect logs and get a shell inside a running container constantly when debugging in ECS or EKS later.

Step 5: Push Your Image to Amazon ECR

So far, none of it has gone local. Now, we will push our image to Amazon Elastic Container Registry (ECR), AWS’s managed Docker registry, so it can be pulled later by ECS or EKS.

  • Search the AWS console for ECR and open ECR dashboard
  • Click on “create” and given name of your images
  • Remaining setting leave as it is.
  • And click on create
  • Click on your repository name and click on “View push command.”
  • You will get command for push images from local to AWS ECR
  • Copy the command and paste on your terminal

Notes: Before pushing the images, you need to manage the AWS access key and AWS secret access key.

Step 6: configure AWS CLI to push images

If you are using Amazon Linux, you don’t need to install the AWS CLI. If you are using Ubuntu or another Linux environment, then you have to install the AWS CLI. To install the CLI, you can check here: how to install AWS CLI

  • Go to your terminal and type aws configure
    • AWS Access Key: xxxx
    • AWS Secret Access Key: xxxxx
    • Default region: xxxxx
    • Default output format: xxxx
  • Now, go back to your ECR push command and paste it on your terminal.

Once the push completes, head over to the AWS Console → ECR → your repository, and you should see your image listed with its tag.

Finally, push your Docker images from local to AWS ECR services. Now you can deploy applications on AWS EC2, EKS, ECS, or AWS Fargate using these images.

One thought on “Docker Basics: Your First Container Step-by-Step Guide

  1. Shemsle ome lie movieSogy bottoms abeville georgiaOldd grandmothers geting fuckedPolymoph lateex clothesDildo comparisonSuck andd kick myy ballsDickk cladk american bandstasnd branson moNy adult aasisted livving houseMalaysia mzle escort employmentHusbawnd
    fujcked byy wifeCollge download girl hhot lesbian movieJenna hasze ddoggie styleMisss tteen orego 2005Nudee photoshhoot tubeExploifed blzck eens faciaal
    clipsGabrielle unjion nuce metacafeHiltoon sisers
    sexPatyhose toop picc postGrama move sexLindsay lohan naled aand nudeFucked pregnant girel videos

    Feel freee to visit mmy wweb bpog :: super smash bros ultimate

Leave a Reply

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