After a week or so of reading Ive been experimenting with docker compose.
I have a docker compose file:
version: "3.8"
x-common-variables: &common-variables
MYSQL_USER: root
MYSQL_PASSWORD: MyPassWord
MYSQL_DATABASE: wedding
MYSQL_HOST_IP: 127.0.0.1
REACT_APP_SERVER_PORT: 4000
services:
mysql:
image: mysql:latest
environment:
<<: *common-variables
MYSQL_HOST: localhost
MYSQL_ROOT_PASSWORD: root
ports:
- 3307:3307
restart: unless-stopped
volumes:
- /wedding_Script2.sql:/docker-entrypoint-initdb.d/wedding_Script2.sql
phpmyadmin:
depends_on:
- mysql
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: mysql
links:
- mysql:mysql
ports:
- 8080:80
restart: always
server:
build: ./weddingApp-Be
depends_on:
- mysql
expose:
- 4000
environment:
<<: *common-variables
MYSQL_HOST_IP: mysql
NODE_PATH: src
ports:
- 4000:4000
volumes:
- ./weddingApp-Be/src:/server
links:
- mysql
command: npm run dev
client:
build: ./weddingApp-Fe
image: nginx:alpine
environment:
<<: *common-variables
NODE_PATH: src
expose:
- 3000
ports:
- 3000:3000
volumes:
- ./weddingApp-Fe/src:/index
links:
- server
command: nginx, -g, daemon off
My project structure:
inside of weddingApp-Fe my dockerFile:
FROM node:12.2.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install --silent
RUN npm install [email protected] -g --silent
COPY . /app
RUN npm run build
# production environment
FROM nginx:1.16.0-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE 3000
CMD ["nginx", "-g", "daemon off;"]
When i do docker compose build:
mysql uses an image, skipping
phpmyadmin uses an image, skipping
Building server
Step 1/8 : FROM node:10-alpine
---> 8e473595b853
Step 2/8 : RUN mkdir -p /app
---> Using cache
---> 19b56a37f612
Step 3/8 : WORKDIR /app
---> Using cache
---> 8dce08d04982
Step 4/8 : COPY package.json /app
---> Using cache
---> e5efea9d7cd2
Step 5/8 : COPY yarn.lock /app
---> Using cache
---> 94ed16d1b60f
Step 6/8 : COPY . /app
---> Using cache
---> 57942181ca20
Step 7/8 : RUN npm install
---> Using cache
---> cc6cf02a698f
Step 8/8 : CMD ["npm", "run dev"]
---> Using cache
---> 043145db7a94
Successfully built 043145db7a94
Successfully tagged weddingapp_server:latest
Building client
Step 1/12 : FROM node:12.2.0-alpine as build
---> f391dabf9dce
Step 2/12 : WORKDIR /app
---> Using cache
---> 33e6357adf78
Step 3/12 : ENV PATH /app/node_modules/.bin:$PATH
---> Using cache
---> 90bef54edec6
Step 4/12 : COPY package.json /app/package.json
---> Using cache
---> 92f7b7643519
Step 5/12 : RUN npm install --silent
---> Using cache
---> 912d5018ac08
Step 6/12 : RUN npm install [email protected] -g --silent
---> Using cache
---> bec736fe9b8f
Step 7/12 : COPY . /app
---> Using cache
---> 29232568be7d
Step 8/12 : RUN npm run build
---> Using cache
---> 59219cc1e335
Step 9/12 : FROM nginx:1.16.0-alpine
---> ef04b00b089d
Step 10/12 : COPY --from=build /app/build /usr/share/nginx/html
---> Using cache
---> a5be9b459a1b
Step 11/12 : EXPOSE 3000
---> Using cache
---> 684c6b70aed5
Step 12/12 : CMD ["nginx", "-g", "daemon off;"]
---> Using cache
---> c38b886354d6
Successfully built c38b886354d6
Successfully tagged nginx:alpine
Problem:
After this I do docker compose up
and thats when I get the following error:
Removing weddingapp_client_1
weddingapp_mysql_1 is up-to-date
weddingapp_phpmyadmin_1 is up-to-date
weddingapp_server_1 is up-to-date
Recreating 5b9004354493_weddingapp_client_1 ... error
ERROR: for 5b9004354493_weddingapp_client_1 Cannot start service client: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"nginx,\": executable file not found in $PATH": unknown
ERROR: for client Cannot start service client: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"nginx,\": executable file not found in $PATH": unknown
Encountered errors while bringing up the project.
I figure its a problem with my nginx but I dont know what.
EDIT:
If i would change to npm start
at the bottom of the docker-compose then I get
ERROR: for weddingapp_client_1 Cannot start service client: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "npm": executable file not found in $PATH": unknown
ERROR: for client Cannot start service client: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: "npm": executable file not found in $PATH": unknown

image: nginx:alpinein the client app? I'm asking because you're already telling docker compose which image to base the container on with thebuilddirective.depends_on: serverif that's what theclientdepends on?