Deploying containers in a swarm environment: Access to Portainer

Access to Portainer

Portainer is a management tool used to create and manage docker containers. When databases and file contents are copied to the NFS mounting point, you will have to access to the Portainer with your research user. 

After authentication, your home page will be similar to this one:

Create a Stack

On the left side, it will be a menu with different options. Go to “Stacks” and then click to “Add stack”:

Choose the web editor build method with a Stack name composed by your RESEARCH_GROUP-project_name:

 

Create a Docker image

Every container needs a Docker image, which is used to deploy the services. You can use:

Create a Docker Compose file

The Docker Compose file should have this structure and must include all these parameters:

version: '3'      # compose file version. it is only compatible from 3.0 to 3.3
services:         # services definition 

  http:              # container name
    image: php:7.0-apache   # docker image name from docker hub repository or your own image uploading 
                             to registry.sb.upf.edu
    deploy:
      placement: 
        constraints: [node.role == worker]  # it is essential this constraint definition. 
                                            it is in charge of running containers on docker machines
      replicas: 1

      resources:     #  resources definition: cpu, memory, container restart policy, etc
        limits:
          cpus: "0.5"
          memory: 256M

      restart_policy:
        condition: on-failure
    ports:               

      - 8600:80       # port used for the container. we will provide you this number
    volumes:
      - volume_name:/var/www/html  # "volume_name" is the network map name and "/var/www/html" is 
                                      the container directory for html data
    restart: always
    networks:
      - project_name-network            # "project_name-network" is the network used to connect the 
                                        containers. replace "project_name" with the name of your project
volumes: 
  volume_name:
    driver: nfs
    driver_opts:
      share: 10.80.110.223:/RESEARCH_GROUP/docker/project_name/html  # network map where the data will be stored. 
                                                                     It is a persistent volume
                                                           
networks:
  project_name-network:


When you finish the compose file, click on "Deploy the stack". In this example, there is only one container that is pointing to a network share, but in the same stack we can have more than one container. If we have multiple containers will be defined in the same stack and can communicate with each other through the network defined in the stack.

At the final of this page you can download an example file (it has been tested): 

Here, you have the Compose template. Since it is a .yml file extension, be careful with indents if you copy-paste some parts.

Container states

When you deploy a container, it is possible to obtain these states:

  • New: The task is initialized.
  • Pending: Resources for the task were allocated.
  • Assigned: Docker assigned the task to nodes.
  • Accepted/Rejected: The task was accepted/rejected by a worker node.
  • Preparing: Docker is preparing the task.
  • Starting: Docker is starting the task.
  • Running: A currently running container.
  • Complete: The task exited without an error code.
  • Created: A container that has been created.
  • Restarting: A container that is restarting.
  • Paused: A container whose processes have been paused.
  • Failed: The task exited with an error code.
  • Shutdown: Docker requested the task to shut down.
  • Orphaned: The node was down for too long.
  • Dead: A container that the daemon has failed to stop.