I have a Dockerfile that uses node alpine image
in order i wrote a docker-compose.yml file which copy nginx.conf and builds the docker container successfully, but when i run docker-compose up, first it creates services, as i can
curl http://localhost:80
and receive the valid answer form nginx but in docker-compose console, it hangs in attaching stage:
Recreating tree-react-app_tree-app_1 … done
Creating tree-react-app_proxy_1 … done
Attaching to tree-react-app_tree-app_1, tree-react-app_proxy_1
tree-app_1 | 2019/10/18 09:41:58 [emerg] 1#1: “user” directive is not allowed here in /etc/nginx/conf.d/default.conf:1
tree-app_1 | nginx: [emerg] “user” directive is not allowed here in /etc/nginx/conf.d/default.conf:1
Here are my docker files:
FROM node:12-alpine as build
RUN apk update && \
apk add --no-cache util-linux
RUN mkdir /app
# install dependencies
COPY package.json /app/
WORKDIR /app
# copythe project
COPY . /app/
RUN yarn install
ENV NODE_ENV=development
ARG REACT_APP_SERVER_ADDR
# copy and build the project
RUN yarn build
# next stage: prepare production environment
FROM nginx:alpine
ENV NODE_ENV=production
RUN mkdir -p /app/current && \
chown -R nginx:nginx /app
COPY --from=build --chown=nginx:nginx /app/build /app/current
COPY --from=build --chown=nginx:nginx /app/nginx.conf /etc/nginx/conf.d/default.conf
and docker-compse.yml
version: "3.3"
services:
tree-app:
build:
context: .
dockerfile: Dockerfile
tty: true # for beautiful debug and pretty error output
stdin_open: true # not working with up command
environment:
- NODE_ENV=development
- REACT_APP_SERVER_ADDR=http://localhost:3333
ports:
- 3000:3000
proxy:
image: nginx:1.13-alpine
ports:
- 80:80
restart: always
links:
- tree-app
ps: with this docker-compose tool, i can build and run the other containers in my local machine