'How to run the application on 80 port?
I have a react app running on AWS as Docker container managed by Kubernetes. It also uses nginx, I'm not sure for what.
When I upload my local changes to GitLab repo, it every time deploys on 8000 port of my ec2 machine. I don't want that my app's url has :8000 in it, can anybody help me with it? What exactly affects on application's port?
Dockerfile
# build environment
FROM node:13.12.0-alpine as build
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json ./
COPY package-lock.json ./
#RUN npm install --legacy-peer-deps
RUN npm install
RUN npm install [email protected] -g
COPY . ./
RUN npm run build
# production environment
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
COPY fullchain.crt /etc/ssl/fullchain.crt
COPY unpluggedapp.key.pem /etc/ssl/unpluggedapp.key.pem
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
docker-compose
version: '3'
services:
admin:
image: registry.gitlab.com/......:<VERSION>
environment:
REACT_APP_URL: .......
ports:
- 80:80
- 8443:443
restart: on-failure
nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/errors.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/accesses.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
listen [::]:80;
server_name admin-dev.unpluggedsystems.app;
# return 301 http://$server_name$request_uri;
root /usr/share/nginx/html;
index index.html;
location /api/7/apps/search {
proxy_pass http://ws75.aptoide.com/api/7/apps/search;
proxy_set_header X-Forwarded-For $remote_addr;
}
location ~ \.(apk)$ {
proxy_pass https://pool.apk.aptoide.com;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
}
.gitlab-ci.yml
stages:
- build
- deploy
services:
- docker:stable-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
REGISTRY_URL: registry.gitlab.com/......
DOCKER_BUILD_ID: ${CI_COMMIT_SHORT_SHA}
CONTAINER: ./container.txt
image: node:latest
Build image:
stage: build
tags:
- runner
image: docker:git
services:
- docker:stable-dind
script:
- docker login ${REGISTRY_URL} -u ${CI_REGISTRY_USER} -p ${CI_REGISTRY_PASSWORD}
- docker build --network host -t ${REGISTRY_URL}:${DOCKER_BUILD_ID} .
- docker push ${REGISTRY_URL}:${DOCKER_BUILD_ID}
only:
- dev
- master
Deploy:
stage: deploy
tags:
- runner
before_script:
- 'command -v ssh-agent || ( apt-get update -qy && apt-get install openssh-client -y )'
- eval `ssh-agent -s`
- mkdir -p ~/.ssh
- chmod 700 ~/.ssh
- echo "Lkey.pem" >> ~/.ssh/Lkey.pem
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
- chmod 400 Lkey.pem
- chmod 400 ~/.ssh/Lkey.pem
- ssh -T -i "Lkey.pem" [email protected]
script:
- ssh -T -i "Lkey.pem" [email protected] "cd client; sed -E -i 's/(.*up_admin_client:).*/\1${DOCKER_BUILD_ID}/' docker-compose.yml ; docker-compose up -d"
only:
- dev
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
