Comments (11)
Hi @barbalex, npm run backend:start
should start containers for postgres and electric that are named <app name>-postgres-1
and <app name>-electric-1
. When running npm run db:migrate
the script checks that those containers are running but it appears they are not. You said the containers seem to be named postgres-1
and electric-1
which is odd as they are missing the app name prefix.
A few things to check:
- Can you check the container names with
docker container ls
to make sure the names arepostgres-1
andelectric-1
(i.e. are missing the app name prefix) - If the container names are missing the app name prefix, can you check the contents of the
backend/compose/.envrc
file. It is in this file that an environment variable is defined that contains the app name, e.g.:
export POSTGRESQL_IMAGE=postgres:14-alpine
export APP_NAME=bug_repro
export ELECTRIC_PORT=5134
export ELECTRIC_PROXY_PORT=65431
export ELECTRIC_IMAGE=electricsql/electric@sha256:4f21be46b836c6f3a59649cf6c8d03479c5df45ef28012c51d61706cfd8d2892
Notice the APP_NAME
environment variable, this should be picked up by our compose file (cf. https://github.com/electric-sql/electric/blob/main/examples/starter/template/backend/compose/docker-compose.yaml#L2):
name: "${APP_NAME:-electric}"
The way how these environment variables are picked up is because when running npm run backend:start
we invoke our dockerCompose
helper function (https://github.com/electric-sql/electric/blob/main/examples/starter/template/util/util.js#L34) which passes the envrc file using the --env-file
option.
Since you mentioned that you are on Windows, perhaps there is a problem with the paths that we define to the compose file and to the envrc file:
const envrcFile = path.join(__dirname, '../backend/compose/.envrc')
const composeFile = path.join(__dirname, '../backend/compose/docker-compose.yaml')
You may want to console.log
them in your app and manually try to run the compose file as how our dockerCompose
function would do, to see if there's a problem there.
from electric.
Regarding container names: The problem was my container noobness:
PS C:\Users\alexa\ps> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8f6966d545f5 electricsql/electric:latest "/app/bin/entrypoint…" 19 hours ago Up 30 seconds 0.0.0.0:5133->5133/tcp, 0.0.0.0:65432->65432/tcp ps-electric-1
dd15cedf6d46 postgis/postgis:16-3.4 "docker-entrypoint.s…" 19 hours ago Up 30 seconds (healthy) 0.0.0.0:53411->5432/tcp ps-postgres-1
I didn't understand how they are named and saw this:
So they are named correctly. Sorry for the noise.
More in next comment.
from electric.
To find out more, I added a console.log in db/util.js/fetchHostPort:
const envrcFile = path.join(__dirname, '../backend/compose/.envrc')
const composeFile = path.join(
__dirname,
'../backend/compose/docker-compose.yaml',
)
console.log('util.js, fetchHostPort', {
container,
containerPort,
service,
envrcFile,
composeFile,
output: `docker inspect --format='{{(index (index .NetworkSettings.Ports "${containerPort}/tcp") 0).HostPort}}' ${container}`,
})
the output part was copied from the shell.exec command of fetchHostPort itself.
This returns:
util.js, fetchHostPort {
container: 'ps-electric-1',
containerPort: 65432,
service: 'Electric',
envrcFile: 'C:\\Users\\alexa\\ps\\backend\\compose\\.envrc',
composeFile: 'C:\\Users\\alexa\\ps\\backend\\compose\\docker-compose.yaml',
output: `docker inspect --format='{{(index (index .NetworkSettings.Ports "65432/tcp") 0).HostPort}}' ps-electric-1`
}
When I manually run a text.js file with this content:
const shell = require('shelljs')
shell.exec(
`docker inspect --format='{{(index (index .NetworkSettings.Ports "65432/tcp") 0).HostPort}}' ps-electric-1`,
)
I get this error:
PS C:\Users\alexa\ps> node test.js
template parsing error: template: :1: unclosed action
from electric.
Oh, seems to be a windows quoting thing: https://stackoverflow.com/a/38886047/712005
from electric.
I have tried these versions, all failed, with different errors:
shell.exec(
`docker inspect --format="{{(index (index .NetworkSettings.Ports \"65432/tcp\") 0).HostPort}}" ps-electric-1`,
) // template parsing error: template: :1: unexpected "/" in operand
shell.exec(
`docker inspect --format="{{(index (index .NetworkSettings.Ports ""65432/tcp"") 0).HostPort}}" ps-electric-1`,
) // template parsing error: template: :1: unterminated quoted string
shell.exec(
`docker inspect --format="{{(index (index .NetworkSettings.Ports "65432/tcp") 0).HostPort}}" ps-electric-1`,
) // template parsing error: template: :1: unexpected "/" in operand
shell.exec(
`docker inspect --format="{{(index (index .NetworkSettings.Ports /"65432/tcp/") 0).HostPort}}" ps-electric-1`,
) // template parsing error: template: :1: unexpected "/" in operand
shell.exec(
`docker inspect --format="{{(index (index .NetworkSettings.Ports '65432/tcp') 0).HostPort}}" ps-electric-1`,
)
// template parsing error: template: :1: unexpected "/" in operand
// template parsing error: template: :1: malformed character constant: '65432/tcp'
Seems fun to execute commands in the shell (would that be powershell?) on windows...
from electric.
I found the documentation on the docker inspect --format
command: https://docs.docker.com/config/formatting/
So pasting this command directly into powershell works:
docker inspect --format='{{(index (index .NetworkSettings.Ports \"65432/tcp\") 0).HostPort}}' ps-electric-1
(returns: 65432)
But running this file does not:
const shell = require('shelljs')
shell.exec(
`docker inspect --format='{{(index (index .NetworkSettings.Ports \"65432/tcp\") 0).HostPort}}' ps-electric-1`,
)
error:
PS C:\Users\alexa\ps> node test.js
template parsing error: template: :1: unclosed action
from electric.
I wonder if the docker command could be written without using --format
. That might be a way to prevent the error? Unfortunately that seems not to be documented: https://docs.docker.com/engine/reference/commandline/inspect/#find-a-specific-port-mapping.
I know nothing about go templates unfortunately.
from electric.
This is the command we execute (cf. https://github.com/electric-sql/electric/blob/main/examples/starter/template/db/util.js#L51):
`docker inspect --format="{{(index (index .NetworkSettings.Ports \\"${containerPort}/tcp\\") 0).HostPort}}" ${container}`
Note the double backslashes before the double quotes \\"${containerPort}/tcp\\"
It's a double backslash because we need to escape the "
so we want to write \"
but \
is a special escape character in JS string so we need to escape the backslash \\"
Does that work?
from electric.
Calling a test.js file containing this works:
const shell = require('shelljs')
shell.exec(
`docker inspect --format="{{(index (index .NetworkSettings.Ports \\"65432/tcp\\") 0).HostPort}}" ps-electric-1`,
)
(Pasting it directly into powershell gives: template parsing error: template: :1: unexpected "\\" in operand
)
from electric.
So it seems that line has recently changed. In the new version of the app I built using create-electric-app
today, that line is correct. Now it works on windows for me.
Well, actually, that means: I am now getting this error on windows too: #750
from electric.
So it seems that line has recently changed. In the new version of the app I built using
create-electric-app
today, that line is correct. Now it works on windows for me.Well, actually, that means: I am now getting this error on windows too: #750
Great! Yes, we knew we had some issues with Windows but @samwillis fixed them recently. Glad that those fixes address this issue.
from electric.
Related Issues (20)
- npm ERR! Cannot read properties of null (reading 'matches') HOT 3
- Improve client generation failure messages at the client level HOT 1
- Delayed/Failure to read your writes, lost writes are common HOT 4
- when select where item contains in json array, array_constiains key not recognize, how to filter if json type constains element HOT 2
- Can't load data when phone is offline in Expo app HOT 5
- [BUG] Syntax error CREATE_REPLICATION_SLOT when install electric-sql with docker HOT 8
- MODULE ERROR: Electric.Replication.PostgresConnector HOT 5
- Possible issue in the new ShapeManager code. HOT 3
- SQLite/PGLite not fully compatible with NextJS HOT 4
- Inactive replication slot causing warnings on DO managed Postgres HOT 6
- Demo example with PostGis plugin?? HOT 1
- Error: FOREIGN KEY constraint failed HOT 4
- [rpc] recv: #SatInStartReplicationResp{`Error: Cannot catch up to the server's current state`} HOT 1
- Unable to install electric-sql on MacOS & Node@22 HOT 2
- Zod rejects UUIDs that Postgres deems valid HOT 1
- `(FunctionClauseError) no function clause matching in Electric.Postgres.Extension.SchemaCache.name/1` HOT 7
- too many arguments on function json_object HOT 2
- Issue with ElectricSQL when I try to change the content of an entry in the database HOT 3
- tauri-sqlite example start failed HOT 2
- Secure auth invalid key HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from electric.