Consider the docker-compose
file:
version: '3.0'
volumes:
data:
driver: local
networks:
simple-network:
driver: bridge
services:
postgres:
container_name: postgres
image: postgres
restart: unless-stopped
environment:
POSTGRES_DB: node-crud
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
volumes:
- data:/var/lib/postgresql/data
networks:
- simple-network
api:
container_name: api
image: api
restart: unless-stopped
build:
context: simple-node-api
dockerfile: Dockerfile
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- DATABASE=node-crud
- USERNAME=postgres
- PASSWORD=postgres
- HOST=postgres
networks:
- simple-network
depends_on:
- postgres
With the api's Dockerfile:
FROM node:latest
WORKDIR /api
COPY package.json .
COPY yarn.lock .
COPY init.sh .
RUN yarn install
COPY . .
ENTRYPOINT ["./init.sh"]
And the init.sh
script:
#!/bin/sh
yarn run migrate
yarn run start
When I run docker-compose up
the output is:
Creating network "simple-example_simple-network" with driver "bridge"
Creating postgres ... done Creating api ... done Attaching to postgres, api
api | standard_init_linux.go:211: exec user process caused "no such file or directory"
postgres |
postgres | PostgreSQL Database directory appears to contain a database; Skipping initialization
postgres |
postgres | 2020-11-25 13:35:12.683 UTC [1] LOG: starting PostgreSQL 13.1 (Debian 13.1-1.pgdg100+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 8.3.0-6) 8.3.0, 64-bit
postgres | 2020-11-25 13:35:12.683 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432
postgres | 2020-11-25 13:35:12.684 UTC [1] LOG: listening on IPv6 address "::", port 5432
postgres | 2020-11-25 13:35:12.698 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
postgres | 2020-11-25 13:35:12.719 UTC [24] LOG: database system was shut down at 2020-11-25 13:34:01 UTC
postgres | 2020-11-25 13:35:12.738 UTC [1] LOG: database system is ready to accept connections
api exited with code 1
api exited with code 1
api exited with code 1
api exited with code 1
api exited with code 1
Gracefully stopping... (press Ctrl+C again to force)
Stopping api ... done Stopping postgres ...
Killing postgres ...
ERROR: Aborting.
I'm working under Windows 10, why is it producing no such file or directory
even though the file exists in the path?
Entrypoint should be absolute path.
Try:
ENTRYPOINT ["/api/init.sh"]
Be sure that /api/init.sh
have the +x
exec bit set.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.