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

- 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
- you give port mapping i.e. host port and container port
- 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


* 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

* 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


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)

- 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

- Execute commands in interactive terminal


