2. Set up a new project¶

    In the Divio Cloud Control Panel, create a new project.

    For the purposes of this tutorial, select the following options for yourproject (other options can be left on their default settings):

    • Python: Python 3.x
    • Project type: Django
      Once the project has been created, deploy the Test server, and then login tothe admin.

    Note

    By logging in, you will add your 3. Divio Cloud single-sign-on user to theproject’s database, and will be able to log in to the site locally withouthaving to add the new user to the database manually.

    You’ll see a familiar Django admin for a new site.

    Now let’s replicate this project locally.

    List your cloud projects:

    Identify the slug of the project you created in the previous step, and use thiswith the command, for example:

      Note

      Various processes will unfold, taking a few minutes (see for a description of them).

      cd into the newly-created project directory, where you will find a mostly-familiar Django project.

      Start the project:

      divio project up will also open the project in a web browser once it’s upand running.

      Note

      If you didn’t previously log in to the Cloud site before setting up theproject locally, you’ll need to add a user to the database before you canlog in. The Divio Cloud SSO system allows you todo this from the Django login page.

      As you proceed through this tutorial, you will inevitably encounter theoccasional issue. There are some commands that will help you when this happens.

      You already know how to start your project with the divio command (divio
      project up
      , above). We’ll be introducing two new tools in this section:

      • docker
      • docker-compose
        This may seem a complex combination of commands, but through practice you willstart to understand when and how to use each one. Try them now to becomefamiliar with them.

      Check what Docker processes are running:

      1. docker ps
      2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME
      3. d6007edbaf32 demoproject_web "/tini -g -- pytho..." 17 minutes ago Up 8 seconds 0.0.0.0:8000->80/tcp demoproject_web_
      4. 27ff3e661027 postgres:9.4 "docker-entrypoint..." 6 days ago Up 8 seconds 5432/tcp demoproject_db_

      Now docker ps should show that neither the web nor containersare running (see the formore information using the Docker tool).

      2.3.2. Using docker-compose¶

      You can also start the project with the , a command for working with projects (we willspecify that we want to bring up the web service described in the project’sThe docker-compose.yml file file, which also launches the dbservice):

      1. docker-compose up web
      2. Performing system checks...
      3.  
      4. System check identified 1 issue (0 silenced).
      5. June 21, 2017 - 05:48:10
      6. Django version 1.8.18, using settings 'settings'
      7. Starting development server at http://0.0.0.0:80/
      8. Quit the server with CONTROL-C.

      This is a good thing to do while developing, because it gives you the consoleoutput in your terminal, so you can see what’s going on.

      When you stop it with CONTROL-C, the web service will stop, but thedb service will remain running. On the other hand, if you start theproject with docker-compose up, then when you stop it with CONTROL-C,both containers will stop.

      Note

      To make matters more complicated, under certain circumstances, the webcontainer may continue running after exiting from the command. Invoking and exiting it again will usually stop it.

      Now you can also run a command in a specific container, such as:

      which will open bash right in the web container. (—rm means removethe container when exiting; —service-ports tells it to expose the portslisted in the docker-compose.yml.) And you can run:

        at the container’s bash prompt as another way of running the project andgetting the output.