Reputation: 696
I have a react build and a server build (mongo) e.g
- root
- server
-build
DockerFile
-client
-build
DockerFile
docker-compose.yml
This uses github actions on push to build and deploy to an AWS instance
The server is running fine on prod on a seperate port however I'm missing something to be able to run my client on this host. I dont want to serve all my static assets through my express api if I can help it.
Docker compose file:
version: '3'
services:
client:
build:
context: ./client
dockerfile: Dockerfile
volumes:
- /app/node_modules
- ./client:/usr/src/app
ports:
- '3000:3000'
restart: on-failure
container_name: spacer_app_client
tty: true
stdin_open: true
server:
build:
context: ./server
dockerfile: Dockerfile
ports:
- '3001:3001'
restart: on-failure
container_name: spacer_app_server
stdin_open: true
volumes:
- /app/node_modules # Inside the container, don't try to override this folder, just leave as is
- ./server:/usr/src/app # Look at the server directory and copy everything into the app folder in the container
Upvotes: 0
Views: 50
Reputation: 4000
You can add an nginx (or what ever other webserver you want to your docker compose:
First go to dockerhub (https://hub.docker.com/), then search "nginx" or whatever you look name is named. Look for an official image. you'll get something like: https://hub.docker.com/_/nginx
In the documentation page they explain how to run an official nginx server instance with docker by command line like:
docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx
Ideally you fix the version to have predictive behavior. The doc provide you with the available one. Let get the latest stable one:
docker run --name some-nginx -v /some/content:/usr/share/nginx/html:ro -d nginx:1.19.1
They explain how to do that with docker-compose too with an example:
web:
image: nginx:1.19.1
volumes:
- ./templates:/etc/nginx/templates
ports:
- "8080:80"
environment:
- NGINX_HOST=foobar.com
- NGINX_PORT=80
Of course you would adapt the volume, port and alike to your liking.
Remark: there thousand of available containers on dockerhub for most database, operating systems, server, build toolchain and alike. So you can run directly python or java app or a web server or whatever that you like with a bit ofconfig.
Upvotes: 1