Assigning ports to containers in docker

Assigning ports to containers in docker

the containers we create should be accessible to the outer world so we port containers to our main ip

the default port of apache webserver is 80 so we can use the below command to port
docker run -it -p <port>:80 imagename
for example, let us create an apache image

1.make a directory name with name abc

mkdir abc

2.go into the abc dirctory

cd /abc

3.create a docker file

nano dockerfile

4.paste the below code

FROM ubuntu:16.04
LABEL maintainer="admin@codeskulls.org"
RUN apt-get update \
&& apt-get install -y apache2
COPY html/* /var/www/html/
WORKDIR /var/www/html
CMD ["apachectl", "-D", "FOREGROUND"]
EXPOSE 80

5.run the build command

docker build .

6.give the port for the server ip

docker run -it -p 8080:80 <imagename>

7.now open your browser and trigger http://yourip:8080

Last updated on by vishal devxo