Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems using 'exec', and interacting with postgres #116

Open
jkhartshorne opened this issue Jun 24, 2020 · 3 comments
Open

Problems using 'exec', and interacting with postgres #116

jkhartshorne opened this issue Jun 24, 2020 · 3 comments
Labels

Comments

@jkhartshorne
Copy link

I'm having difficulty using compose.exec. Part of this is because I think the docs are wrong. Here's what docs say:

exec(container, command, options)

However, you definitely have to include information about the docker-compose.yaml. This at least runs:

compose.exec('test_db', psql, {cwd: path.join(initDir, 'pushkin'), config: 'docker-compose.dev.yml'}, '-U postgres', -c 'create database test_db')

However, I get the following error:

'psql: FATAL: role "root" does not exist\n'

So it looks like the -U tag is being ignored. I also tried doing it this way:

compose.exec('test_db', psql -U postgres -c 'create database test_db', {cwd: path.join(initDir, 'pushkin'), config: 'docker-compose.dev.yml'})

with the same result. Here's the critical part of my docker-compose:

test_db:
image: 'postgres:11'
environment:
POSTGRES_PASSWORD: example

Since I didn't set a root user, docker goes with the default 'postgres'. However, trying to set the user to 'root' didn't help:

test_db:
image: 'postgres:11'
environment:
POSTGRES_USER: root
POSTGRES_PASSWORD: example

@jkhartshorne
Copy link
Author

OK. I think this was a docs problem. The following seems to be working:

compose.exec('test_db', ['psql', '-U', 'postgres', '-c', 'create database test_db'], {cwd: path.join(initDir, 'pushkin'), config: 'docker-compose.dev.yml'})

with the following docker-compose:

test_db:
image: 'postgres:11'
environment:
POSTGRES_PASSWORD: example

@Steveb-p
Copy link
Contributor

docker-compose.dev.yml is definitely not a standard name for configuration file. This library doesn't do anything fancy with configuration files and relies on normal execution of docker-compose binary.
This means that by default docker-compose.y[a]ml and docker-compose.override.y[a]ml files are loaded, just as the docker-compose docs say.

https://docs.docker.com/compose/extends/#understanding-multiple-compose-files

By default, Compose reads two files, a docker-compose.yml and an optional docker-compose.override.yml file.

@jkhartshorne
Copy link
Author

Sure. But for various reasons, I needed to run this command not from the directory where the yaml is. In any case, it turns out that compose.exe() will take options to use a different location and name. It's just not documented. Also, it looks like the documentation on how to specify the command itself is at the very least incomplete, but probably outright wrong. (The one example shows the command presented as a single string, whereas I could only get it to work as an an array of strings.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants