Reputation: 3172
I followed the instructions at Digital Ocean's "How To Install Nginx on Ubuntu 14.04 LTS", which states that Nginx should be running as soon as it is installed, but the following Dockerfile:
FROM ubuntu:14.04.2
RUN apt-get update -y
RUN apt-get -y install curl
RUN apt-get -y install nginx
RUN curl http://127.0.0.1 | grep "Welcome to nginx!"
gives me this error:
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused
To reproduce this:
/whatever/path/Dockerfile
This will build the docker container using Ubuntu, install Nginx, then try to connect to 127.0.0.1:80 returns the Nginx welcome page. That is where the "connection refused" error occurs.
My question is: how can I call "curl http://127.0.0.1 from within my container and get a response?
This issue on my project is https://github.com/dcycleproject/dcyclebox/issues/1
Upvotes: 0
Views: 1316
Reputation: 35109
Don't forget to start nginx
first:
RUN service nginx start && curl http://127.0.0.1 | grep "Welcome to nginx!"
Upvotes: 1
Reputation: 22680
Instruction on digital ocean talking about OS with running services which are not running in docker container (and they should not). When you building image you only installing necessary software. Then you should run container based on this image - and usually only one process is running in container. Look at official nginx image for example - https://github.com/dockerfile/nginx/blob/master/Dockerfile
Also it is a bad practice to run apt-get update and apt-get install in different RUN commands - https://docs.docker.com/articles/dockerfile_best-practices/#run
Upvotes: 1