2
votes

I have been trying for several days now to run CKAN as a docker image. The official CKAN documentation explains in detail how to create your own docker image via "docker-compose". The basic workflow is:

  1. Clone the CKAN source files from GitHub
  2. Make some changes in the "docker-compose.yml" file (custom passwords, extensions, etc)
  3. Run "docker-compose"

This gives you a running CKAN docker container together with all the necessary databases and search engines.

My ultimate goal however is to push this CKAN docker image to Docker-Hub and to run it on other machines via "docker run". I want to use this apporach because I want to extensively modify the original CKAN installation, and also add custom datasets, groups and organizations to the running catalog before pushing it to docker hub. "Docker run" seems to be much easier and more convenient compared to using "Docker compose".

The problem is: Whenever I try to run the CKAN container using the commands below I end up with the following error:

$ docker run -d --name db ckan/postgresql
$ docker run -d --name solr ckan/solr
$ docker run -d -p 80:80 --link db:db --link solr:solr ckan/ckan

ERROR: no CKAN_SQLALCHEMY_URL specified in docker-compose.yml

The CKAN_SQLALCHEMY_URL is definitely present in the docker-compose.yml file. Setting this variable as global PATH variable in windows did not help either. I also tried different versions of the CKAN source. Since the CKAN documentation only explains how to use "docker-compose" and not how to use "docker run", I suspect that "docker run" is simply not possible. If this is true, why is there a official CKAN image on the Docker Hub? (This throws the exact same error as if I build the image myself using "docker-compose") What is the purpose of this image on the Docker Hub if it can't be used?

Is there any way to "docker run" the CKAN image once it is built?

Thanks!

Edit: Below is my CKAN docker-compose.yml file. (Variables are stored in the .env file)

# docker-compose build && docker-compose up -d
# If "docker-compose logs ckan" shows DB not ready, run "docker-compose restart ckan" a few times.
version: "3"

volumes:
  ckan_config:
  ckan_home:
  ckan_storage:
  pg_data:

services:
  ckan:
    container_name: ckan
    build:
      context: ../../
      args:
          - CKAN_SITE_URL=${CKAN_SITE_URL}
    links:
      - db
      - solr
      - redis
    ports:
      - "0.0.0.0:${CKAN_PORT}:5000"
    environment:
      # Defaults work with linked containers, change to use own Postgres, SolR, Redis or Datapusher
      - CKAN_SQLALCHEMY_URL=postgresql://ckan:${POSTGRES_PASSWORD}@db/ckan
      - CKAN_DATASTORE_WRITE_URL=postgresql://ckan:${POSTGRES_PASSWORD}@db/datastore
      - CKAN_DATASTORE_READ_URL=postgresql://datastore_ro:${DATASTORE_READONLY_PASSWORD}@db/datastore
      - CKAN_SOLR_URL=http://solr:8983/solr/ckan
      - CKAN_REDIS_URL=redis://redis:6379/1
      - CKAN_DATAPUSHER_URL=http://datapusher:8800
      - CKAN_SITE_URL=${CKAN_SITE_URL}
      - CKAN_MAX_UPLOAD_SIZE_MB=${CKAN_MAX_UPLOAD_SIZE_MB}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - DS_RO_PASS=${DATASTORE_READONLY_PASSWORD}

    volumes:
      - ckan_config:/etc/ckan
      - ckan_home:/usr/lib/ckan
      - ckan_storage:/var/lib/ckan

  datapusher:
    container_name: datapusher
    image: clementmouchet/datapusher
    ports:
      - "8800:8800"

  db:
    container_name: db
    build:
      context: ../../
      dockerfile: contrib/docker/postgresql/Dockerfile
      args:
        - DS_RO_PASS=${DATASTORE_READONLY_PASSWORD}
        - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    environment:
      - DS_RO_PASS=${DATASTORE_READONLY_PASSWORD}
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
    volumes:
      - pg_data:/var/lib/postgresql/data

  solr:
    container_name: solr
    build:
      context: ../../
      dockerfile: contrib/docker/solr/Dockerfile


  redis:
    container_name: redis
    image: redis:latest
1
Can you post your docker-compose.yml file, please? It looks it's not defined in environment variables. - Alejandro Galera
@AlejandroGalera I attached my docker-compose.yml file. This is the one that I use during "docker-compose". Do I need another one for "docker run"? If so how do I use it? - Wolfgang Deigele

1 Answers

1
votes

run it as a docker compose command if you want to run it from docker you need to split away docker files and send some arguments from .env file like error says SQL_ALCHEMY is not being sent.

i would recommend to execute it as docker compose. then once you build from docker compose you can just execute docker run and send missing arguments like SQL_ALCHEMY.