Hi Readers, Docker is an open source platform adopted widely to ease the developing, shipping, and running applications. Docker has a object named containers isolates the applications from the infrastructure and avoids any external affect on the development environment.
In this blog we will see some network part of containers.
We will see how to enable communication of the container to the outside world or to the other containers.
We do this by exposing ports and mapping these ports.
Letβs see how we can do that.
- Login into the AWS account and create one Linux Instance
- ssh into the instance
Run these commands
sudo su
yum update -y
Install the Docker
- yum install docker -y
Start the Docker service
- service docker start
Now our base machine is ready.
We will create a server named as demoserver with port(publish) 80 expose map the host port no 80 with container port no 80.
- docker run -td --name demoserver -p 80:80 ubuntu
Check the running containers.
- docker ps
To get the details of the port we have exposed.
- docker port demoserver
Execute the container and go inside the container by starting a new process.
docker exec -it demoserver /bin/bash
apt-get update
- apt-get install apache2 -y
Then move to this path and create an index.html file
cd /var/www/html
echo "HELLO WORLD">index.html
Now start the apache2 service
- service apache2 start
Copy the public IP of the instance
And run on the browser now
The contents of the index file is now visible.
Top comments (0)