martin
02/12/2018, 12:49 PMnilan
02/12/2018, 12:51 PMmartin
02/12/2018, 12:54 PMandre
02/12/2018, 1:52 PMandre
02/12/2018, 1:53 PMmartin
02/12/2018, 2:13 PMandre
02/12/2018, 2:14 PMmartin
02/12/2018, 2:15 PMmartin
02/12/2018, 2:16 PMandre
02/12/2018, 2:16 PMmartin
02/12/2018, 2:16 PMandre
02/12/2018, 2:16 PMandre
02/12/2018, 2:17 PMmartin
02/12/2018, 2:17 PMandre
02/12/2018, 2:17 PMö
.andre
02/12/2018, 2:18 PMandre
02/12/2018, 2:19 PMmartin
02/12/2018, 2:21 PMnpm start
. And I’m trying to run my whole server inside of a docker container.andre
02/12/2018, 2:22 PMmartin
02/12/2018, 2:25 PMconnection: '<postgres://localhost/devblog>'
. How I establish my connection.andre
02/12/2018, 2:26 PMdocker-compose.yml
file here?martin
02/12/2018, 2:30 PMmartin
02/12/2018, 2:30 PMversion: "3"
services:
redis:
image: redis
networks:
- webnet
db:
image: postgres
networks:
- webnet
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: martinnord
POSTGRES_DB: devblog
web:
image: devblog-server
ports:
- 3010:3010
networks:
- webnet
environment:
DB_HOST: db
REDIS_HOST: redis
command: ["./wait-for-it.sh", "db:5432", "--", "node", "index.js"]
networks:
webnet:
andre
02/12/2018, 2:32 PMdb
is actually the hostname with which you can reach the database from other containers.andre
02/12/2018, 2:32 PMDB_HOST
environment variable and pass it to your database connector.martin
02/12/2018, 2:32 PMandre
02/12/2018, 2:33 PMmartin
02/12/2018, 2:33 PMandre
02/12/2018, 2:33 PMenvironment
section you define environment variables
which can be used by the actual application that runs within the container.martin
02/12/2018, 2:33 PMdb
and then pass it into my knexfileandre
02/12/2018, 2:33 PMmartin
02/12/2018, 2:34 PMconnection: '<postgres://db/devblog>'
?andre
02/12/2018, 2:34 PMprocess.env.<VAR>
andre
02/12/2018, 2:34 PMandre
02/12/2018, 2:34 PMprocess.env.DB_HOST
andre
02/12/2018, 2:34 PMandre
02/12/2018, 2:34 PMpostgres://${process.env.DB_HOST}/devblog
martin
02/12/2018, 2:35 PMDB_HOST
variables value will be db
?andre
02/12/2018, 2:36 PMmartin
02/12/2018, 2:37 PMKnex: Timeout acquiring a connection. The pool is probably full.
. :Smartin
02/12/2018, 2:38 PMdocker-compose up
andre
02/12/2018, 2:38 PMandre
02/12/2018, 2:38 PMmartin
02/12/2018, 2:39 PMandre
02/12/2018, 2:40 PMmartin
02/12/2018, 2:45 PMdocker-compose up
?andre
02/12/2018, 2:45 PMmartin
02/12/2018, 2:45 PMRecreating backend_web_1 ...
Starting backend_db_1 ...
Starting backend_db_1 ... done
Attaching to backend_web_1, backend_redis_1, backend_db_1
web_1 | wait-for-it.sh: waiting 15 seconds for db:5432
redis_1 | 1:C 12 Feb 14:35:54.163 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1 | 1:C 12 Feb 14:35:54.170 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 12 Feb 14:35:54.171 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1 | 1:M 12 Feb 14:35:54.174 * Running mode=standalone, port=6379.
redis_1 | 1:M 12 Feb 14:35:54.175 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 12 Feb 14:35:54.175 # Server initialized
redis_1 | 1:M 12 Feb 14:35:54.179 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
redis_1 | 1:M 12 Feb 14:35:54.187 * DB loaded from disk: 0.008 seconds
redis_1 | 1:M 12 Feb 14:35:54.188 * Ready to accept connections
db_1 | 2018-02-12 14:35:54.299 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2018-02-12 14:35:54.300 UTC [1] LOG: listening on IPv6 address "::", port 5432
db_1 | 2018-02-12 14:35:54.310 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1 | 2018-02-12 14:35:54.358 UTC [20] LOG: database system was interrupted; last known up at 2018-02-12 14:04:32 UTC
web_1 | wait-for-it.sh: db:5432 is available after 2 seconds
db_1 | 2018-02-12 14:35:54.929 UTC [21] LOG: incomplete startup packet
db_1 | 2018-02-12 14:35:55.090 UTC [20] LOG: database system was not properly shut down; automatic recovery in progress
db_1 | 2018-02-12 14:35:55.103 UTC [20] LOG: redo starts at 0/1634B00
db_1 | 2018-02-12 14:35:55.104 UTC [20] LOG: invalid record length at 0/1634B38: wanted 24, got 0
db_1 | 2018-02-12 14:35:55.105 UTC [20] LOG: redo done at 0/1634B00
db_1 | 2018-02-12 14:35:55.190 UTC [1] LOG: database system is ready to accept connections
web_1 |
web_1 | App listening on 3010
web_1 | Env: undefined
martin
02/12/2018, 2:45 PMandre
02/12/2018, 2:47 PMconsole.log(process.env.DB_HOST)
in the section where you start your application? Your application entry point.martin
02/12/2018, 2:47 PMmartin
02/12/2018, 2:47 PMmartin
02/12/2018, 2:49 PMindex.js
file and when I run docker-compose up
I got no output, but when I just npm run dev
I can see it saying db
thereandre
02/12/2018, 2:50 PMandre
02/12/2018, 2:50 PMandre
02/12/2018, 2:50 PMandre
02/12/2018, 2:50 PMmartin
02/12/2018, 2:51 PMdocker build -t devblog-server .
andre
02/12/2018, 2:51 PMweb
as follows:andre
02/12/2018, 2:52 PMandre
02/12/2018, 2:53 PMweb:
image: node:8-alpine
command: “node /app/index.js”
volumes:
- “.:/app”
working_dir: “/app”
ports:
- 3010:3010
environment:
DB_HOST: db
REDIS_HOST: redis
andre
02/12/2018, 2:54 PMdocker-compose.yml
lives) into the container at /app
andre
02/12/2018, 2:54 PMandre
02/12/2018, 2:55 PMvolume
mounting .:/app
to match your needs.martin
02/12/2018, 2:56 PMmap
dir here 😅martin
02/12/2018, 2:57 PMandre
02/12/2018, 2:58 PMmartin
02/12/2018, 2:58 PMPulling web (node:8-alpine)...
8-alpine: Pulling from library/node
605ce1bd3f31: Already exists
d6ade540dd0b: Pull complete
7608b7ec7a5f: Pull complete
Digest: sha256:b1e1f024dccf7058d2f55b21d6bf65c9cb932ba7bee2a24eca08ddb7c654312b
Status: Downloaded newer image for node:8-alpine
Recreating backend_web_1 ...
Starting backend_db_1 ...
Recreating backend_web_1 ... done
Attaching to backend_db_1, backend_redis_1, backend_web_1
db_1 | 2018-02-12 14:57:16.427 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
db_1 | 2018-02-12 14:57:16.427 UTC [1] LOG: listening on IPv6 address "::", port 5432
redis_1 | 1:C 12 Feb 14:57:16.400 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
db_1 | 2018-02-12 14:57:16.430 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
redis_1 | 1:C 12 Feb 14:57:16.400 # Redis version=4.0.8, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1 | 1:C 12 Feb 14:57:16.400 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
db_1 | 2018-02-12 14:57:16.444 UTC [21] LOG: database system was interrupted; last known up at 2018-02-12 14:48:43 UTC
redis_1 | 1:M 12 Feb 14:57:16.401 * Running mode=standalone, port=6379.
web_1 | env: can't execute 'bash': No such file or directory
db_1 | 2018-02-12 14:57:16.580 UTC [21] LOG: database system was not properly shut down; automatic recovery in progress
redis_1 | 1:M 12 Feb 14:57:16.401 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1 | 1:M 12 Feb 14:57:16.401 # Server initialized
redis_1 | 1:M 12 Feb 14:57:16.401 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
db_1 | 2018-02-12 14:57:16.582 UTC [21] LOG: invalid record length at 0/1634CC0: wanted 24, got 0
redis_1 | 1:M 12 Feb 14:57:16.401 * DB loaded from disk: 0.000 seconds
redis_1 | 1:M 12 Feb 14:57:16.401 * Ready to accept connections
db_1 | 2018-02-12 14:57:16.583 UTC [21] LOG: redo is not required
db_1 | 2018-02-12 14:57:16.596 UTC [1] LOG: database system is ready to accept connections
backend_web_1 exited with code 127
andre
02/12/2018, 2:58 PMdocker logs backend_web_1
gives you?martin
02/12/2018, 3:00 PMandre
02/12/2018, 3:00 PMmartin
02/12/2018, 3:01 PMenv: can't execute 'bash': No such file or directory
andre
02/12/2018, 3:01 PMshebang
in the first line of the index.js
?martin
02/12/2018, 3:02 PMandre
02/12/2018, 3:03 PMmartin
02/12/2018, 3:04 PMandre
02/12/2018, 3:05 PMmartin
02/12/2018, 3:06 PMmartin
02/12/2018, 3:06 PMandre
02/12/2018, 3:06 PMandre
02/12/2018, 3:08 PMmartin
02/12/2018, 3:08 PMandre
02/12/2018, 3:15 PMandre
02/12/2018, 3:16 PMandre
02/12/2018, 3:16 PMnpm run build && docker-compose up
andre
02/12/2018, 3:17 PMandre
02/12/2018, 3:17 PMandre
02/12/2018, 3:17 PMmartin
02/12/2018, 3:19 PMandre
02/12/2018, 3:20 PMandre
02/12/2018, 3:21 PMmartin
02/12/2018, 3:21 PMandre
02/12/2018, 3:21 PMGraphQL Playground
or GraphiQL
.martin
02/12/2018, 3:21 PMnpm run build && docker-compose up
martin
02/12/2018, 3:21 PMandre
02/12/2018, 3:22 PMmartin
02/12/2018, 3:22 PMandre
02/12/2018, 3:23 PMmartin
02/12/2018, 3:24 PMApp listening on 3010
Env: undefined
and then you got data?martin
02/12/2018, 3:24 PMandre
02/12/2018, 3:24 PMmartin
02/12/2018, 3:26 PMandre
02/12/2018, 3:27 PMmartin
02/12/2018, 3:31 PMandre
02/12/2018, 3:33 PMmartin
02/12/2018, 3:33 PMandre
02/12/2018, 3:36 PMmartin
02/12/2018, 3:39 PMnpm run dev
and it also times outandre
02/12/2018, 3:41 PMmartin
02/12/2018, 3:47 PMandre
02/12/2018, 3:48 PMmartin
02/12/2018, 3:59 PMhost
in the connection
object who’s messing it upandre
02/12/2018, 3:59 PMmartin
02/12/2018, 4:00 PMlocalhost
there instead of process.env.DB_HOST
and it worked when I tried npm run dev
againandre
02/12/2018, 4:00 PMnpm run dev
. Yes, in this case the application runs on your machine instead of in a container on your machine.martin
02/12/2018, 4:01 PM