Docker compose is used to run multiple containers. In this tutorial, Using Docker compose example for NGINX and MYSQL. I used Docker compose version “3”
“Build, Manage and Secure Your Apps Anywhere. Your Way.” Quote from docker!
Docker compose example
Creating Docker-compose file. All docker compose file is a YAML file. Now, let’s go create the docker-compose.yml file as below
[root@DevopsRoles ~]# mkdir docker-instance [root@DevopsRoles ~]# cd docker-instance/ [root@DevopsRoles docker-instance]# vim docker-compose.yml
The content docker-compose file as below
version: '3' services: WEB01: image: nginx:latest container_name: "web01" hostname: web01 ports: - "8888:80" - "8443:443" - "2233:22" #deploy: # resources: # limits: # memory: 512M #mem_limit: 512m volumes: - ./data_web01:/mnt_nfs networks: - bridge restart: always DB01: image: mysql:latest container_name: "db01" hostname: db01 ports: - "33306:3306" - "2234:22" command: --default-authentication-plugin=mysql_native_password environment: MYSQL_ROOT_PASSWORD: 123456789 #MYSQL_USER=huupv #MYSQL_PASSWORD=passforhuupv #MYSQL_DATABASE=DevopsRolesDB #deploy: # resources: # limits: # memory: 512M volumes: - ./data_db01:/mnt_nfs networks: - bridge restart: always volumes: web_mnt_nfs: driver: local networks: bridge: driver: bridge ipam: config: - subnet: 192.168.12.0/24
Creating and starting a container
[root@DevopsRoles docker-instance]# docker-compose up -d
The screen output terminal:
Creating network "docker-instance_bridge" with driver "bridge" Creating db01 ... done Creating web01 ... done
The result, Docker compose example
Access browser Nginx server
![docker compose example nginx](https://www.devopsroles.com/wp-content/uploads/2018/08/docker-compose-example-nginx.jpeg)
Checking running containers for nginx and mysql
![docker compose example](https://www.devopsroles.com/wp-content/uploads/2018/08/docker-compose-example.jpeg)
Conclusion
Thought the article, you can use “Docker compose example” as above. I hope will this your helpful. Thank you for reading the DevopsRoles page!