How to create nginx container by using docker compose
[ec2-user@ip-172-31-95-65 ~]$ sudo -i
[root@ip-172-31-95-65 ~]# vi docker-compose.yml
[root@ip-172-31-95-65 ~]# cat docker-compose.yml
version: '3'
services:
webapp1:
image: nginx
ports:
- "8000:80"
[root@ip-172-31-95-65 ~]# docker-compose up -d ------To run the docker compose file
[ec2-user@ip-172-31-95-65 ~]$ sudo -i
[root@ip-172-31-95-65 ~]# vi docker-compose.yml
[root@ip-172-31-95-65 ~]# cat docker-compose.yml
version: '3'
services:
webapp1:
image: nginx
ports:
- "8000:80"
[root@ip-172-31-95-65 ~]# docker-compose up -d ------To run the docker compose file
[root@ip-172-31-95-65 ~]# docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
89992e0f59e7 nginx "nginx -g 'daemon of…" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp root_webapp1_1
[root@ip-172-31-95-65 ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
7263963a2ee3 bridge bridge local
6e7b7c015f1e host host local
a8d46c14262d none null local
3c94972e3a5f root_default bridge local
Now to delete all the resource which are created by docker compose file
[root@ip-172-31-95-65 ~]# docker-compose down
Stopping root_webapp1_1 ... done
Removing root_webapp1_1 ... done
Removing network root_default
[root@ip-172-31-95-65 ~]#
-------------------------------------------------------------------------------------------------------------
Now create two container by use of docker compose
[root@ip-172-31-95-65 ~]# vi docker-compose.yml
[root@ip-172-31-95-65 ~]# cat docker-compose.yml
version: '3'
services:
webapp1:
image: nginx
ports:
- "8000:80"
webapp2:
image: nginx
ports:
- "8001:80"
[root@ip-172-31-95-65 ~]# docker-compose up
If you change any particlar line then only taht container will re-create and reaming will be same like i am going to cahne port nuber of conatiner two
[root@ip-172-31-95-65 ~]# vi docker-compose.yml
[root@ip-172-31-95-65 ~]# cat docker-compose.yml
version: '3'
services:
webapp1:
image: nginx
ports:
- "8000:80"
webapp2:
image: nginx
ports:
- "8002:80"
[root@ip-172-31-95-65 ~]# docker-compose up -d
root_webapp1_1 is up-to-date
Recreating root_webapp2_1 ... done
No comments:
Post a Comment