snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.03k stars 3.18k forks source link

docker-compose.yml with only slightly modified parameters from the boilerplate in docs. #6346

Closed Leopere closed 5 years ago

Leopere commented 6 years ago

Please confirm you have done the following before posting your bug report:

Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Use included Docker-compose.yml file
  2. Attempt to load snipe-it with virtually the same configuration in the docker documentation
  3. Load up what looks like a faceplant. https://i.imgur.com/d6fY3hU.png

Expected behavior I want a docker-compose file version of the docker command line suggestions from the documentation. Unfortunately, it seems that this is too much to ask from a PHP application.

docker-compose.yml

version: '3.4'

networks:
  traefik:
    external: true

services:
  snipe-mysql:
    image: 'mysql:5.6'
    env_file: .env
    volumes:
      - './data:/var/lib/mysql'
  snipeit:
    image: snipe/snipe-it
    ports:
      - '8765:80'
    expose:
      - 80
    links:
      - 'snipe-mysql:mysql'
    env_file: .env
    volumes:
      - './data:/var/lib/snipeit'
    labels:
      # https://docs.traefik.io/user-guide/docker-and-lets-encrypt/
      - "traefik.backend=snipe-it"
      - "traefik.docker.network=traefik"
      - "traefik.frontend.rule=Host:snipe-it.nixc.us"
      - "traefik.expose=true"
      - "traefik.port=80"

Server (please complete the following information):

Error Messages

Additional context

HinchK commented 6 years ago

@Leopere please enable debugging by editing your .env & adding:

APP_DEBUG=true
WARN_DEBUG=false

That will direct a "Whoops" application-error details zto the screen. These errors are always logged to storage/log/laravel.log, which should be accessible via a docker exec -i -t snipeit cat storage/logs/laravel.log

I am also running into issues getting this docker-compose off the ground - yet for seemingly different reasons. I will keep working on it - this is a good step forward toward a unified docker-compose process, I appreciate your taking the time to create this issue and bring this to our attention!

HinchK commented 6 years ago

I am going to guess your error was either a database connection error (e.g. "getaddrinfo"), or an error from the application about tables or app_keys.

After running docker-composer config - I was able to figure out where I went wrong.

In short, it's important to treat the environment files being passed to the containers as a systems-level environment; just the laravel-specific environment settings (e.g. MAIL_HOST, APP_KEY) is not enough in order to spin up the MySQL Container properly.

I create a unique (.env) file, specifically to make it simple to spin up both my database and application containers using one unified environment containing the necessary system/mysql settings + the laravel specific settings.

My hinchk_local_docker.env file: https://gist.github.com/HinchK/bc2fee6d442489b9cf77f50c8cd08d14

docker-compose.yml

version: "3.4"
services:
  snipeit:
    env_file: ./hinchk_local_docker.env
    image: snipe/snipe-it
    depends_on:
      - mysql
    ports:
      - "80:80"
    volumes:
      - data:/var/lib/snipeit
  mysql:
    env_file: ./hinchk_local_docker.env
    image: mysql:5.6
    volumes:
      - database:/var/lib/mysql
    ports:
      - "3306:3306"
volumes:
  data: {}
  database: {}

I then ran:

docker-compose up

and was up and running:

image

The traefik settings appear to be half-connected, as there is no existing docker-network of that name in a fresh docker environment. I might be missing something; I will keep tinkering, as well as following up with @uberbrady towards the automation of the SSL-endpoint termination particulars.

While I'm not sure I can recommend using this 2-container Snipe-IT Service model for large production environments....for small projects or for development I think it would be a great resource to have a clean docker-compose.yml for our docker-enthusiasts out there!

Leopere commented 6 years ago

Ah, thanks so much for your diligence @HinchK much appreciated for your time and effort with this. If we get this to a point where you're happy I think I'd be willing to fork and submit a PR with the docker-compose.yml content if you don't wish to.

I had only sent part of my docker-compose stuff if you like I can send the other compose file, my docker-compose clusters are all fairly modular and most of them are web-apps that are automagically recognized by Traefik as it's hooked into docker.sock.

The idea is that all I need to do is provide a cname that points at the Traefik reverse proxies.

I know that there are better ways to spin up the networking but usually, I use: docker network create -d bridge --subnet=10.5.0.10/16 Traefik

Then my Traefik config looks something like this: traefik.toml

debug = true

logLevel = "ERROR"
defaultEntryPoints = ["https","http"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
  [entryPoints.https.tls]

[retry]

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "my.domain.com"
watch = true
exposedbydefault = false

[acme]
email = "admin@my.domain.com"
storage = "/opt/traefik/acme.json"
entryPoint = "https"
OnHostRule = true
[acme.httpChallenge]
entryPoint = "http"

# Ping definition for enabling healthcheck
[ping]
  # Name of the related entry point
  #
  # Optional
  # Default: "traefik"
  #
  entryPoint = "traefik"

docker-compose.yml for Traefik

version: '3.4'

networks:
  traefik:
    external: true

services:
#################
## Proxy container ##
#################
## One of the major contributing guides here.
## https://www.digitalocean.com/community/tutorials/how-to-use-traefik-as-a-reverse-proxy-for-docker-containers-on-ubuntu-16-04
## To-Do
## Put the Proxy only on the Orange network and make that work for all backend stuff.
## Put everything that needs secured on the traefik network and anything public should just be directly exposed but all things should have https.
  proxy:
    image: traefik:alpine
    command: --api --docker --docker.domain=docker.localhost --logLevel=DEBUG
    networks:
      traefik:
        ipv4_address: 10.5.0.100
    ports:
      - target: 80
        published: 80
        mode: host
      - target: 443
        published: 443
        mode: host
    expose:
      - 8080
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.toml:/traefik.toml
      ## This is going to be stored by default in the following host dir in staging.
      #  There is a rate limit for how many issuances you can request per week.
      #  Because of this we will store the acme.json file persistently.
      #  In production we are going to need to figure out how it'll work with Kubernetes or variant.
      - ./traefik/:/opt/traefik/
    labels:
      # https://docs.traefik.io/user-guide/docker-and-lets-encrypt/
      - "traefik.backend=proxy"
      - "traefik.docker.network=traefik"
      - "traefik.frontend.rule=Host:monitor.nixc.us"
      - "traefik.expose=true"
      - "traefik.port=8080"
    healthcheck:
       test: ["CMD", "traefik", "healthcheck"]
       timeout: 10s
       retries: 3
Leopere commented 6 years ago

Also, a sidenote:

While I do appreciate the usage of volumes I tend to prefer mounting a directory within my docker-compose git repository as for the most part if I was doing something in proper production it would be significantly more docker-swarm or kubernetes compatible.

Leopere commented 6 years ago

I suppose I've got it mostly working. I'm getting a couple of red flags in the first page diagnostic part of the setup. image

Okay, so what works is the following.

Docker-compose.yml

version: '3.4'

networks:
  traefik:
    external: true

services:
  snipe-mysql:
    image: 'mysql:5.6'
    env_file: .env
    volumes:
      - './data:/var/lib/mysql'
    networks:
      - traefik
  snipeit:
    image: snipe/snipe-it
    ports:
      - '8765:80'
    expose:
      - 80
    links:
      - 'snipe-mysql:mysql'
    env_file: .env
    volumes:
      - './data:/var/lib/snipeit'
    labels:
      # https://docs.traefik.io/user-guide/docker-and-lets-encrypt/
      - "traefik.backend=snipe-it"
      - "traefik.docker.network=traefik"
      - "traefik.frontend.rule=Host:snipe-it.nixc.us"
      - "traefik.expose=true"
      - "traefik.port=80"
    networks:
      - traefik

Run

 docker network create -d bridge --subnet=10.5.0.10/16 Traefik

Traefik Configuration

Then use the Traefik configuration from earlier while changing the appropriate variables.

HinchK commented 5 years ago

@Leopere Just wanted to check-in with you on this issue. I'm not sure if you have submitted a PR - with your permission I would be up to submitting a docker-compose-ability feature on our shared behalf :+1:

Mostly inquiring if you have had any issues with cron-jobs on your docker containers (I may open up another issue related to this.)

Leopere commented 5 years ago

I've not really deployed this anywhere but you're welcomed to reach out to me async to GitHub somehow if you have a place to recommend we discuss it further. I have to write a proposal surrounding it at some point soon.

jannik-kramer commented 5 years ago

Same problem here. I'm facing the url problem like Leopere on 20 Oct. I traefik is setting the X-Forward-Proto and ist set under the trusted proxies. Still no luck.

Leopere commented 5 years ago

@jannik-kramer have a look at what worked for me

stale[bot] commented 5 years ago

Is this still relevant? We haven't heard from anyone in a bit. If so, please comment with any updates or additional detail. This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Don't take it personally, we just need to keep a handle on things. Thank you for your contributions!

barrycurr commented 4 years ago

Just in case anyone else comes here and is running into issues running from a docker-compose.yml file, I had the same issue and found the solution to be that within the environment parameters a line needs to be added for: - DB_HOST=<name of mysql service>

This is because the database is being looked for at localhost but won't be found.

Below is a pretty complete docker-compose.yml if people want it. I had pre-created my volumes hence the external:true lines:

version: "3.3"

services:

    snipeit:
        image: snipe/snipe-it
        container_name: snipeit
        ports:
            - "9090:80"
        volumes:
            - "vol_snipeit:/var/lib/snipeit"
        depends_on:
            - snipeit_mysql
        links:
            - snipeit_mysql:mysql
        environment:
            #
            # Mysql Parameters
            #
            - DB_HOST=snipeit_mysql
            - MYSQL_ROOT_PASSWORD=<password>
            - MYSQL_DATABASE=<database>
            - MYSQL_USER=<db_user>
            - MYSQL_PASSWORD=<db_password>
            #
            # Email Parameters
            #
            - MAIL_PORT_587_TCP_ADDR=
            - MAIL_PORT_587_TCP_PORT=
            - MAIL_ENV_FROM_ADDR=
            - MAIL_ENV_ENCRYPTION=tcp
            - MAIL_ENV_USERNAME=
            - MAIL_ENV_PASSWORD=
            #
            # Snipe-IT Settings
            #
            - APP_ENV=production
            - APP_DEBUG=false
            - APP_KEY=base64:<key>
            - APP_URL=http://<url>:9090
            - APP_TIMEZONE=
            - APP_LOCALE=

    snipeit_mysql:
            image: mysql:5.6
            container_name: snipeit_mysql
            volumes:
                - "vmfs_mysql_snipeit:/var/lib/mysql"   
            environment:
                #
                # General Parameters
                #
                - MYSQL_ROOT_PASSWORD=<password>
            command: ['mysqld', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci']

volumes:
    # Pre-created MySQL SnipeIT Volume
    vol_snipeit_mysql:
        external: true
    # Pre-created SnipeIT Volume
    vol_snipeit:
        external: true