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

      b. You get the long container ID for your app and then are kicked back to your terminal. Your container is running in the background. You can also see the abbreviated container ID with docker container ls (and both work interchangeably when running commands):

        $ docker container ls

          CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

          9979d09fe820 activemq "/bin/sh -c './apach…" 6 seconds ago Up 5 seconds 1883/tcp, 5672/tcp, 8161/tcp, 61613-61614/tcp, 61616/tcp, 0.0.0.0:4000->1884/tcp vigorous_galileo

      c. Now use docker container stop to end the process, using the CONTAINER ID, like so:

        $ docker container stop 9979d09fe820

  So far, we have successfully created a image of activemq and successfully run it by a container. If you want to share your image, you can take the following steps.

  Share your image

    To demonstrate the portability of what we just created, let’s upload our built image and run it somewhere else. After all, you need to know how to push to registries when you want to deploy containers to production.

    A registry is a collection of repositories, and a repository is a collection of images—sort of like a GitHub repository, except the code is already built. An account on a registry can create many repositories. The docker CLI uses Docker’s public registry by default.

    1. Log in with your Docker ID

      $ docker login

    2. Tag the image

      $ docker tag image username/repository:tag

      for example: $ docker tag activemq haizeiwang/activemq:v1

              -haizeiwang is my account name

              -activemq is my remote repository name

              -v1 is my image tag,which is the version number

    3. Publish the image

      $ docker push username/repository:tag

    Once complete, the results of this upload are publicly available. If you log in to Docker Hub, you see the new image there, with its pull command.

    4. Pull and run the image from the remote repository

      $ docker run -p 4000:1884 haizeiwang/activemq:v1

    If the image isn’t available locally on the machine, Docker pulls it from the repository.

    No matter where docker run executes, it pulls your image, along with jdk , and runs your code. It all travels together in a neat little package, and you don’t need to install anything on the host machine for Docker to run it.

三.Build a image of swieApp with Dockerfile

  Repeat the second step,but omit running and sharing.

  1. Edit the Dockerfile

    FROM python:3.7

    ENV PYTHONUNBUFFERED 1

    RUN echo python -V

    RUN mkdir /app

    RUN mkdir /app/db

    COPY . /app

    WORKDIR /app/SwieProject

    RUN pip3 install -r ../requirements.txt

    EXPOSE 8080

    ENTRYPOINT python ./wanlidaserver.py

  (This Dockerfile refers to a couple of files we haven’t created yet, namely wanlidaserver.py and requirements.txt. Let’s create those next.)

  2. Create a file named requirements.txt

    This file provides all the packages that the project needs that Python does not have. When executing the "RUN pip3 install -r ../requirements.txt" command, all the packages in the file will be installed. Put it in the same folder with the Dockerfile. The file contents are as follows:

      pymysql

      DBUtils

      sanic

      paho-mqtt

      pandas

      xlwt

      qrcode

      zplgrf

      xlutils

      requests

      DBUtils

  3. Create your python project

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

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