Problem with connection between nodejs container to mongo container

Hi,
I have some question if it’s possible:
I built a project in Nodejs- in Docker,
And I wont connect it to mongodb container,
the mongo db container run with the data- without problems:

cdrachelllinux@DESKTOP-R9ESLDU:/mnt/c`Preformatted text`/Users/RachelCohen$ docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED        STATUS        PORTS       NAMES
9a3bcc06c95d   mongo     "docker-entrypoint.s…"   12 hours ago   Up 12 hours   27017/tcp   mongodb

The node js project can connect to regular mongodb (not mongo Docker container) ,
and when I connect it to mongo container- with connectionstring,

 mongoose.connect(`process.env.MONGODB_CONNSTRING`,{

and build the node js project image, and run the node project container-
it’s exited immediately

when I checked what is the problem I got:

cdrachelllinux@DESKTOP-R9ESLDU:/mnt/c/Users/RachelCohen/DockerProject/ApiGenerator$ docker run --name kjh -p 3070:3070 r
achelc8/cdcdcdcdcdcdm .
**/usr/local/bin/docker-entrypoint.sh: exec: line 11: .: Permission denied**

the node Dockerfile is:

FROM node:lts-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
EXPOSE 3070
RUN chown -R node /usr/src/app
USER node
CMD ["npm", "start"]

when I tried this:

chmod +x entrypoint.sh

I got:

chmod: cannot access 'entrypoint.sh': No such file or directory

and when I added entrypoint to the Dockerfile:

FROM node:lts-alpine
ENV NODE_ENV=production
WORKDIR /usr/src/app
COPY ["package.json", "package-lock.json*", "npm-shrinkwrap.json*", "./"]
RUN npm install --production --silent && mv node_modules ../
COPY . .
EXPOSE 3070
RUN chown -R node /usr/src/app
USER node
**ENTRYPOINT ["/docker-entrypoint.sh"]**
CMD ["npm", "start"]

(and build and ran again) I got:

cdrachelllinux@DESKTOP-R9ESLDU:/mnt/c/Users/RachelCohen/DockerProject/ApiGenerator$ docker run --name kcdjh -p 3070:3070
 rachelc8/cdcdcdcdcdcdmp .
docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "/docker-entrypoint.sh": stat /docker-entrypoint.sh: no such file or directory: unknown.
ERRO[0002] error waiting for container: context canceled

If you know what the problem is-
It will help me a lot!
thank you!

chmod: cannot access 'entrypoint.sh': No such file or directory

Try giving full path:

chmod +x /usr/local/bin/docker-entrypoint.sh

Also, keep your entrypoint.sh in the current directory i.e. the same directory where you keep your Dockerfile. Then use the COPY command in the Dockerfile. Say:

....
...
COPY ./docker-entrypoint.sh /
ENTRYPOINT ["/docker-entrypoint.sh"]
....
..

Hi!
first- thank you very much!

second-
didn’t find the entrypoint,
should I create it myself ? how?
thank you!

Yes, if you write a script, you need to create the docker-entrypoint.sh file. In that you put all commands that you wanted.