Pgloader: Can't connect to database when running from docker.

Created on 30 Jan 2018  路  4Comments  路  Source: dimitri/pgloader

$docker run --rm --name pgloader --net=host dimitri/pgloader:latest pgloader mysql://root:abc123@localhost/vc postgresql://[email protected]/vc
WARNING:
Couldn't re-execute SBCL with proper personality flags (/proc isn't mounted? setuid?)
Trying to continue anyway.
KABOOM!
FATAL error: Failed to connect to pgsql at "127.0.0.1" (port 5432) as user "tim": Database error: Socket error in "connect": ECONNREFUSED (Connection refused)
An unhandled error condition has been signalled:
   Failed to connect to pgsql at "127.0.0.1" (port 5432) as user "tim": Database error: Socket error in "connect": ECONNREFUSED (Connection refused)




What I am doing here?

Failed to connect to pgsql at "127.0.0.1" (port 5432) as user "tim": Database error: Socket error in "connect": ECONNREFUSED (Connection refused)

psql -U tim -h 127.0.0.1
psql (10.1, server 10.0)
Type "help" for help.

postgres=# \q

I tried it without net=host and that too failed.

How can I run this from a docker container and have to be able to connect to my databases?

Most helpful comment

I got this solution working, essentially first create a volume mounting your sqlite database to the running container. Then make sure to specify the IP address that docker recognizes your host machine as (in my case '172.17.0.1'. Otherwise, pgloader tries to connect to localhost inside your docker network.

docker run -v <directory_of_sqlite_on_machine>:<directory_in_container> --rm --name pgloader dimitri/pgloader:latest pgloader --debug  <directory_in_container> postgresql://username:[email protected]:5432/database

All 4 comments

That's a docker networking setup problem, you need to make it so that your container is able to connect to your PostgreSQL database somehow. I'm not fluent enough with docker and tools to help you there, sorry.

@timuckun Try to do something similar (converting from Sqlite3 to Postgresql), and am stuck here as well. I have tried any reasonable combination, and I have the ports published inside the docker images running the Postgresql databases, but did not find a solution. Have you solved the problem for you?

I got this solution working, essentially first create a volume mounting your sqlite database to the running container. Then make sure to specify the IP address that docker recognizes your host machine as (in my case '172.17.0.1'. Otherwise, pgloader tries to connect to localhost inside your docker network.

docker run -v <directory_of_sqlite_on_machine>:<directory_in_container> --rm --name pgloader dimitri/pgloader:latest pgloader --debug  <directory_in_container> postgresql://username:[email protected]:5432/database

This works under docker. Use --network host option.

docker run --rm --network host --name pgloader dimitri/pgloader:latest pgloader -v --debug mysql://root:example@localhost:3306/wordpress postgresql://postgres:postgres@localhost/postgres
version: '3.7'

services:
  db:
    image: postgres:12.1-alpine
    container_name: catchysoft_db
    volumes:
      - ./data:/data
      - postgres_data:/var/lib/postgresql/data/
    ports:
      - "5432:5432"

  mysql_db:
    image: mysql:5.6
    container_name: mysql_db
    environment:
      MYSQL_ROOT_PASSWORD: example
      MYSQL_DATABASE: wordpress
    volumes:
      - ./data:/data
      - mysql_data:/var/lib/mysql      
    ports:
      - "3306:3306"

volumes:
  postgres_data:
  mysql_data:
Was this page helpful?
0 / 5 - 0 ratings

Related issues

benvest picture benvest  路  8Comments

drouarb picture drouarb  路  6Comments

fabswt picture fabswt  路  5Comments

aa8y picture aa8y  路  7Comments

rap2hpoutre picture rap2hpoutre  路  5Comments