0

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 2

1

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

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Mathieu - I launched nginx, but it says: This site can’t be reached localhost refused to connect.
Can you show me exactly what command do you use, and what is your file structure please.
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.
Have you change /pathTo/myApp to your real path ? Try with a simple html page to ensure it's working.
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.
|
1

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

What is the copy destination in Dockerfile if I use Macos env?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.