官术网_书友最值得收藏!

Docker compose script to set up the development environment

Now that we have set up both Tomcat and MySQL as individual containers, let's create a Docker compose script using which both the containers can be started simultaneously, thereby, starting the Dev environment.

  1. Save the following source code as docker-compose.yml in the same folder as the aforementioned files:
    version: '2'
    services:
        web:
          build:
            context: .
            dockerfile: tomcat.df
          ports:
            - "8080:8080"
          volumes:
            - .:/mnt/
          links:
            - db
       db:
          image: mysql:5.7
          ports:
            - "3326:3306"
          environment:
            - MYSQL_ROOT_PASSWORD=r00t
  1. Execute the following command to start and stop the services:
    // For starting the services in the foreground
    docker-compose up

    // For starting the services in the background (detached mode)
    docker-compose up -d

    // For stopping the services
    docker-compose stop
  1. Test whether both the default Tomcat web app and MySQL server can be accessed. Access the URL 192.168.99.100:8080, and make sure that the web page as shown in Figure 1.20 is displayed. Also, open MySQL Workbench and access the MySQL server at IP 192.168.99.100 and port 3326 (as specified in the preceding docker-compose.yml file).
主站蜘蛛池模板: 台北市| 巫溪县| 榆社县| 时尚| 胶州市| 长沙市| 灌阳县| 烟台市| 剑阁县| 巴青县| 阿合奇县| 苏尼特左旗| 福贡县| 资阳市| 永康市| 衡水市| 库尔勒市| 大洼县| 苍溪县| 琼海市| 和静县| 绩溪县| 宾阳县| 唐河县| 大新县| 宣武区| 桂阳县| 仁怀市| 揭阳市| 宁海县| 遵义市| 德兴市| 杨浦区| 长治市| 汝南县| 新蔡县| 河曲县| 怀仁县| 合山市| 六枝特区| 黄山市|