Skip to content

Instantly share code, notes, and snippets.

@hieuphq
Created December 6, 2019 03:05
Show Gist options
  • Save hieuphq/e7dd1a8bc9a07bfd53257db3cb8a211a to your computer and use it in GitHub Desktop.
Save hieuphq/e7dd1a8bc9a07bfd53257db3cb8a211a to your computer and use it in GitHub Desktop.
Deploying a Static HTML Site with Docker and Nginx
#### Build a directory for the website
- For front-end dev who using static files to host your web.
As usually, when you work with react lib, you use bundler(webpack, parcel, browser) to compile your project, you'll get a folder with static file.
What next will we do with those thing? Is it run stand alone locally by open index.html?
Nope, some reason for that is reference files in html follow format '/xxx.js'.It's an absolute path point to:
- public folder for php server
- uri
It should be './xxx.js'
So, you can use dockerfile to build an image with static files. You make a container to run that image.
Finally, you map a machine port to port 80 and enjoy your product at locally
#### Make dockerfile to create an image with static files
```dockerfile
FROM nginx:alpine
COPY . /usr/share/nginx/html
```
#### Build the Docker Image for the HTML Server
Run the following command:
```
docker build -t html-image:v1 .
```
#### Run the Docker Container
Run the following command to run the HTML container server. In this example, I choose a machine port is: 8020
```
docker run -d -p 8020:80 html-image:v1
```
#### Enjoy with that
Open browser with url
```
http://localhost:8020
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment