docker的安装及项目部署 (4)

      Note:If you follow the steps, the database and activeMQ service will start successfully, but you will encounter the problem that the web service fails to start because it cannot connect to the database. This is because you create a database service without data, you need to import the database table structure and data that have been created locally into the Swissmic_WMS database.Do not close the service that has already been started, and then open another terminal.

        1.Export the local Swissmic_WMS database data to the db.sql file in the current directory.

          $ mysqldump -uroot -proot Swissmic_WMS >./db.sql

        2. Make sure you are still at the top level of your new directory. Here’s what ls should show:

          $ ls

            activeMQ db docker-compose.yml db.sql

        3. View information about running containers.

          $ docker ps

            CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

            2fea493b0104 mysql:5.7 "docker-entrypoint.s…" 4 days ago Up 2 hours 33060/tcp, 0.0.0.0:4000->3306/tcp wanlidaapp_db_1

            129c12684fc8 haizeiwang/activemq:v1 "/bin/sh -c './apach…" 4 days ago Up 2 hours 1883/tcp, 5672/tcp, 8161/tcp, 61613-61614/tcp, 61616/tcp, 0.0.0.0:1884->1884/tcp wanlidaapp_activemq_1

        4. Import the db.sql file into the db container

          $ docker cp db.sql wanlidaapp_db_1:/root/ (Note:"wanlidaapp_db_1" is the container name,you can also change to the container ID.)

        5. Go into the container that runs the database

          $ docker exec -ti 2fea493b0104 bash

        6. Switch to the root directory.

          $ cd /root

        7. Import the db.sql file into the Swissmic_WMS database in the container

          $ mysql -u root -p Swissmic_WMS < db.sql

        8. Test data is imported successfully

          $ mysql -u root -p root

            >> use Swissmic_WMS;

            >> show tables;

          If you see the table you want, congratulations, the data import is successful. Otherwise, it is necessary to check from the first step.

            >> exit;

        9. Exit the container

          $ exit

      b. Stop the services

        $ docker-compose stop

      c. Update and run again

        $ docker-compose up

      d. View a running container on another terminal

        $ docker ps

          CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

          9cb77a4c2732 haizeiwang/wanlida_server:v3 "/bin/sh -c 'python …" About a minute ago Up 17 seconds 0.0.0.0:8080->8080/tcp wanlidaapp_web_1

          2fea493b0104 mysql:5.7 "docker-entrypoint.s…" 4 days ago Up 18 seconds 33060/tcp, 0.0.0.0:4000->3306/tcp wanlidaapp_db_1

          129c12684fc8 haizeiwang/activemq:v1 "/bin/sh -c './apach…" 4 days ago Up 19 seconds 1883/tcp, 5672/tcp, 8161/tcp, 61613-61614/tcp, 61616/tcp, 0.0.0.0:1884->1884/tcp wanlidaapp_activemq_1

      Note: If the above result is displayed, it means that all the startups have been successful. You can enter :8080/wms in the browser to test whether the login page appears.

    So far, we have successfully deployed the project service using Method 1. In order to facilitate the direct use of database image in the future, we will recreate a database image using the database container that is running now. Proceed as follows:

      1. Stop the services

        $ docker-compose stop

      2. Convert the database container to a image

        $ sudo docker commit -m "Describe the changed information" -a "author information" 2fea493b0104 haizeiwang/mysql:v1

      3. Upload the image to your remote repository

        $ docker push haizeiwang/mysql:v1

    We will use Method 2 to redeploy the service.

    Method 2: Use the docker stack deploy command

      1. Before we can use the docker stack deploy command we first edit the docker-compose.yml file like this:

        version: "3"

        services:

          db:

            image: haizeiwang/mysql:v1

            expose:

              - "3306"

            volumes:

              - ./db:/var/lib/mysql

            ports:

              - "4000:3306"

            depends_on:

              - activemq


          activemq:

            image: haizeiwang/activemq:v1

            volumes:

              - ./activeMQ:/var/lib/activeMQ

            stdin_open: yes

            tty: yes

            privileged: yes

            ports:

              - "1884:1884"

 

          web:

            image: haizeiwang/wanlida_server:v1

            ports:

              - "8080:8080"

            links:

              - db

              - activemq

            depends_on:

              - db

      2. Create a node of swarm manager, here we use the host as a swarm manager

        $ docker swarm init

      3. Now let’s deploy the project. You need to give your app a name. Here, it is set to SwieApp:

        $ docker stack deploy -c docker-compose.yml SwieApp

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wsxxdf.html