Docker compose example

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

Checking running containers for nginx and mysql

docker compose example

Conclusion

Thought the article, you can use “Docker compose example” as above. I hope will this your helpful.

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.