0

My application requires two docker files. I am building them with docker compose. The compose file is like this

version: '3.4'
services:
  cors:
    container_name: cors
    image: cors:latest
    build:
      context: ./compose/cors-anywhere
      dockerfile: Dockerfile
    user: "node"
    ports:
      - 8081:8081
    command: node server.js
  vite:
    container_name: vite
    image: vite:lts
    build:
      context: ./compose/vite
    user: "node"
    tty: true
    working_dir: /app
    ports:
      - "5173:5173"
    volumes:
      - ./vite/:/app
    command: /start

cors' Dockerfile is like this

ARG NODE_VERSION=lts

FROM node:${NODE_VERSION}

ENV NODE_ENV=production
ENV NODE_PATH=/usr/local/lib/node_modules
ARG version=latest
RUN npm install -g cors-anywhere@$version
COPY server.js .
CMD ["node", "server.js"]

EXPOSE 8081

and vite's docker file is like this

ARG NODE_VERSION=latest

FROM node:${NODE_VERSION}

RUN npm install -g npm@latest

COPY ./entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint

COPY ./start /start
RUN sed -i 's/\r$//g' /start
RUN chmod +x /start

ENTRYPOINT ["/entrypoint"]

vite's entrypoint script is like this

#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

until cd /app && npm install
do
    echo "Retrying npm install"
done

exec "$@"

After the images have been built, when the cors container comes 'up' it logs lots of errors because it is trying to run vite's entrypoint script. I don't understand why entrypoint has been copied to the cors image. Here is the file structure for the cors container

node@d960251bf35e:/$ ls -l
total 80
drwxr-xr-x   1 root root 4096 Jan 11 03:25 bin
drwxr-xr-x   2 root root 4096 Dec  9 19:15 boot
drwxr-xr-x   5 root root  340 Jan 12 10:52 dev
-rwxr-xr-x   1 root root  139 Jan 11 21:59 entrypoint
drwxr-xr-x   1 root root 4096 Jan 12 10:52 etc
drwxr-xr-x   1 root root 4096 Jan 11 07:59 home
drwxr-xr-x   1 root root 4096 Jan 11 03:25 lib
drwxr-xr-x   2 root root 4096 Jan  9 00:00 media
drwxr-xr-x   2 root root 4096 Jan  9 00:00 mnt
drwxr-xr-x   1 root root 4096 Jan 11 07:59 opt
dr-xr-xr-x 211 root root    0 Jan 12 10:52 proc
drwx------   1 root root 4096 Jan 11 07:59 root
drwxr-xr-x   3 root root 4096 Jan  9 00:00 run
drwxr-xr-x   1 root root 4096 Jan 11 03:24 sbin
-rw-r--r--   1 root root 2023 Jan 11 15:24 server.js
drwxr-xr-x   2 root root 4096 Jan  9 00:00 srv
-rwxr-xr-x   1 root root   71 Jan 11 21:59 start
dr-xr-xr-x  13 root root    0 Jan 12 10:52 sys
drwxrwxrwt   1 root root 4096 Jan 11 07:59 tmp
drwxr-xr-x   1 root root 4096 Jan  9 00:00 usr
drwxr-xr-x   1 root root 4096 Jan  9 00:00 var

What am I not understanding?

Dan
  • 1,536
  • 1
  • 10
  • 20
  • In `cors` → `build` → `dockerfile`, are you sure this path is correct and don't leads to `vite`'s Dockerfile ? Sure it shouldn't be `./compose/cors-anywhere/Dockerfile` ? – Pierre Jan 12 '23 at 11:55
  • Thanks @PierreF, according to the (documentation)[https://docs.docker.com/compose/compose-file/build/#context-required] > context defines either a path to a directory containing a Dockerfile, or a url to a git repository. – Dan Jan 13 '23 at 10:25
  • Try to give an absolute path to you `dockerfile:` entry, like `./compose/cors-anywhere/Dockerfile`; or just remove the `dockerfile:` key (same as in `vite` build parth). Give it a try, check if it fix your issue – Pierre Jan 13 '23 at 10:35

0 Answers0