Docker to AWS, A journey

I am following this lecture to build from here:

Docker Image:

Image is a template for creating an environment of your choice, snapshot, has everything to run your apps, OS, software, app code.

Below code we are pulling Apache httpd in docker desktop:

docker pull httpd

Check the images:

docker images

Run container from this image:

docker run httpd:latest

It will hang up so we write ctrl+c to delete it

we check with this code:

docker container ls

docker run

docker run -d httpd:latest

we check:

docker ps


docker container ls

Docker port exposing: before that we are stopping the running container

CONTAINER ID   IMAGE          COMMAND              CREATED              STATUS              PORTS     NAMES
5c14bf083cfe   httpd:latest   "httpd-foreground"   About a minute ago   Up About a minute   80/tcp    objective_roentgen
7c60047c16a0   httpd:latest   "httpd-foreground"   3 minutes ago        Up 3 minutes        80/tcp    intelligent_wiles

docker stop objective_roentgen
docker stop intelligent_wiles

Now writing command for exposing the port and running the container:

docker run -d -p 8080:80 httpd:latest

d for dettach and p for port exposing t

Now the container is running perfectly and exposing the port which we can visit and check with command:

docker ps


CONTAINER ID   IMAGE          COMMAND              CREATED         STATUS         PORTS                  NAMES
46077824c7b4   httpd:latest   "httpd-foreground"   3 seconds ago   Up 2 seconds>80/tcp   boring_chaplygin

Now going to


will work perfectly.

It means the container port 80 is exposing to user by port 8080

Now I stopped the container:

docker stop boring_chaplygin

So cannot reach to localhost:8080
Now we want to run in different port we can also follow the step:

docker run -d -p 8095:80 httpd:latest

Now we can also run multiple containers from a single command:

docker run -d -p 3050:80 -p 8060:80 httpd:latest

We stop and start again the docker container:

docker stop lucid_hodgkin


docker start lucid_hodgkin

now docker help finding:

docker ps --help

it will show like this:

Usage:  docker ps [OPTIONS]

List containers

  -a, --all             Show all containers (default shows just running)
  -f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print containers using a Go template
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
      --no-trunc        Don't truncate output
  -q, --quiet           Only display container IDs
  -s, --size            Display total file sizes

removing a container from here:

docker rm objective_brown

we can show id  by

docker ps -aq

it will show like this:


when we need to remove running container forcefully

docker rm -f container_name

-f for force

Custom name for docker container:

docker run --name website -d -p 3000:80 -p 8080:80 httpd:latest
docker ps

Now stopping docker container named website

docker stop website

Now running again the docker container:

docker start website

we check containers with command

docker ps

Docker ps formatting:

docker ps --format="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"


export FORMAT="ID\t{{.ID}}\nNAME\t{{.Names}}\nIMAGE\t{{.Image}}\nPORTS\t{{.Ports}}\nCOMMAND\t{{.Command}}\t{{.CreatedAt}}\nSTATUS\t{{.Status}}\n"
docker ps --format=$FORMAT

Docker volumes: between host and controllers

cd /mnt/c/Users/Zaki/onedrive/desktop/winter2021/cloud/docker-me
docker run --name docker-me-new -v $(pwd) -d -p 8090:80 httpd:latest

pwd=present working directory

Command for without dockerfile inside:

docker run --name docker-me-new -v $(pwd):/usr/local/apache2/htdocs/ -d -p 8090:80 httpd:latest


Command for with dockerfile inside:

It would be a great help, if you support by sharing :)
Author: zakilive

Leave a Reply

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