2

I'm trying to create a couple of containers with Docker. One is a postgres:latest image and the other is ubuntu:latest image with postgresql-client installed.

I have an existing database cluster in my localhost that I've used before install docker, of course. Now I want to use that cluster in my PostgreSQL container. The path in my computer is /Users/Marco/Data.

I've created a volume too, with the command docker volume create --opt device=/Users/Marco/Data data_container to store the cluster in it.

Then tried to make a docker-compose.ymlfile with the following content:

version: '2' 
services:
 db:
  image: postgres
  environment:
  - PGDATA=/var/lib/postgresql/data/
  ports:
  - "5432:5432"
  volumes:
  - data_container:/var/lib/postgresql/data/pgdata


 shell:
  image: ubuntu_pgsql
  command: /bin/bash
  tty: true
  stdin_open: true 
  links:
  - db

volumes:
 data_container:
  external: true 

When I want to launch the containers with docker-compose up -d it shows me the following error:

ERROR: for db  Cannot start service db: error while mounting volume    '/var/lib/docker/volumes/data_container/_data': error while mounting volume  with options: type='' device='/Users/Marco/Data' o='': no such device
ERROR: Encountered errors while bringing up the project.

What could be failing? Thanks.

1 Answer 1

3

If data container is a directory you should declare as:

volumes:
  - ./data_container:/var/lib/postgresql/data/pgdata

If you used a data_container without ./ before, docker compose understand that is a file, not a directory.

Sign up to request clarification or add additional context in comments.

1 Comment

No, what I want to do exactly is: 1. Map my old cluster into a volume. 2. Use that volume with the PostgreSQL container.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.