Completek8s Classroomnotes 28/Jun/2023

Docker contd

Expose the application running inside docker to external world

  • To Expose the application running inside docker container to external world have a look at below image
    Preview
  • port on a container can be mapped to any free port on the docker host (machine where docker is installed)
  • There are two ways of doing
    • you give port mapping i.e. host port and container port -p <host-port>:<container-port>
    • you ask docker to figure out free port on host and map it to container port -P
  • Create a nginx container with name nginx1 and expose nginx (80) to 8080 port on host
docker container run -d -p 8080:80 --name nginx1 nginx

Preview
Preview
* Create a nginx container with name nginx2 and expose nginx (80) to 8080 port on host while nginx1 is still running. In this we get error as port 8080 is already allocated to some other container

docker container run -d -p 8080:80 --name nginx2 nginx

Preview
* To avoid this confusion, we can ask docker daemon to figure out free port on host and map it.
* Create a nginx container with name nginx3 and expose nginx (80) to any free port on host

docker container run -d -P --name nginx3 nginx
  • Create a nginx container with name nginx4 and expose nginx (80) to any free port on host
    Preview
    Preview

Deleting all the containers using one command and deleting all the images with one command

  • Delete all the containers docker container rm -f $(docker container ls -a -q)
    Preview
  • Delete all the docker images docker image rm $(docker image ls -q)

Activity 1: using inspect command

  • Create a docker container with the following info
    • name: apache1 image: httpd
    • name: alpine1 image: alpine
    • name: mysql1 image: mysql
  • figure out a command to find the ip addresses of each container
  • json to tree view Refer Here
  • docker container inspect apache1 --format "{{ .NetworkSettings.IPAddress }}"

Executing commands in running contianers

  • Execute command
    Preview
  • Execute commands in interactive terminal
    Preview
    Preview

Published
Categorized as Uncategorized Tagged

By continuous learner

devops & cloud enthusiastic learner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Please turn AdBlock off
Social Media Icons Powered by Acurax Web Design Company

Discover more from Direct DevOps from Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading

Visit Us On FacebookVisit Us On LinkedinVisit Us On Youtube