I have static html / AngularJS file. I am going to launch web server with nginx inside docker image. How can I build docker image from these html / Js files and configure nginx server?
2 Answers
Assuming you have this files :
- myApp/
- index.html
- script.js
You need to launch nginx :
docker run -p 8080:80 -v /pathTo/myApp:/usr/share/nginx/html:ro -d nginx
And then access to with http://localhost:8080
More information on nginx docker image
7 Comments
Deimos620
Thanks Mathieu - I launched nginx, but it says: This site can’t be reached localhost refused to connect.
6be709c0
Can you show me exactly what command do you use, and what is your file structure please.
Deimos620
sorry my late reply: - myApp index.dev.html index.html bower_components..... I used: docker run -p 8080:80 -v /pathTo/myApp:/usr/share/nginx/html:ro -d nginx - something same as what you provided.
6be709c0
Have you change
/pathTo/myApp to your real path ? Try with a simple html page to ensure it's working.Deimos620
Yes. I did. I gave absolute path to myApp. I am working on macOS env, So I used: docker run -p 8080:80 -v /absolute/path/To/myApp:/usr/local/nginx/html:ro -d nginx But it says "Welcome to nginx" - not my html, just nginx default html.
|
Try like this :
Step 1 :
You need to create docker file inside the project root.
- myApp/
- Dockerfile
inside the Docker file add below code
FROM nginx:alpine
COPY dist /usr/share/nginx/html
Step 2:
build your project in production mode
Step 3 :
docker login
docker build -t <your registry or image location> .
docker run --name <your project name > -d -p 8080:81 <your registry or image location>
docker push <your registry or image location>
1 Comment
Deimos620
What is the copy destination in Dockerfile if I use Macos env?