Search code examples
dockerdocker-composedockerfiledocker-machine

Docker compose couldn't run static html pages


I have developed some static web-pages using jQuery & bootstrap.Here follows the folder structure,

enter image description here

Using below command i can able to run the docker image

Build the image

docker build -t weather-ui:1.0.0 .

Run the docker image

docker run -it -p 9080:80 weather-ui:1.0.0

Which is working fine and i can able to see the pages using http://docker-host:9080

But i would like to create a docker-compose for it,I have created a docker-compose file like below

version: '2'
services:
  weather-ui:
    build: .
    image: weather-ui:1.0.0
    volumes:
      - .:/app
    ports:
      - "9080:9080"

The above compose file was not working and it stuck,

$docker-compose up


Building weather-ui
Step 1 : FROM nginx:1.11-alpine
---> bedece1f06cc
Step 2 : MAINTAINER ***
---> Using cache
---> ef75a70d43e8
Step 3 : COPY . /usr/share/nginx/html
---> 6fbc3a1d4aff
Removing intermediate container 2dc46f1f751d
Successfully built 6fbc3a1d4aff
WARNING: Image for service weather-ui was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Recreating weatherui_weather-ui_1 ...
Recreating weatherui_weather-ui_1 ... done
Attaching to weatherui_weather-ui_1

It stuck in the above line and i really don't know why it stuck? Any pointers or hint would be great to resolve this issue.

As per Antonio edit,

I can see the running container,

$docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                     NAMES
69ea4ff1a3ea        weather-ui:1.0.2    "nginx -g 'daemon ..."   6 seconds ago       Up 5 seconds        80/tcp, 443/tcp, 0.0.0.0:9080->9080/tcp   weatherui_weather-ui_1

But while launching the page i couldn't see anything.It says the site can't be reached


Solution

  • docker-compose up build your docker container (if not already done) and attach the container to your console.

    If you open your browser, and go to http://localhost:9080, you should see your website.

    You don't need to map a volume : volumes: - .:/app in docker-compose.yml because you already copy static files in Dockerfile :

    COPY . /usr/share/nginx/html 
    

    If you want to launch your container in the background (or in "detached" mode), add -d option : docker-compose up -d.

    And by default docker-compose to not "rebuild" container if already exists, to build new container each time, add --build option : docker-compose up -d --build.