Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I run my docker container with installed Nginx?

I have docker image with Dockerfile, that successfully build with docker build . command. The Dockerfile content is:

FROM ubuntu
RUN apt-get update && apt-get install -y nginx php5 php5-fpm
ADD . /code

How can I run my docker container to see that Nginx is work?

UPDATE: When I try to use next Dockerfile:

FROM ubuntu
RUN apt-get update && apt-get install -y nginx php5 php5-fpm
RUN sudo echo "daemon off;" >> /etc/nginx/nginx.conf
CMD service php5-fpm start && nginx

It build successfully with docker build -t my/nginx ., but when I enter docker run --rm -ti my/nginx command, my terminal not response:

enter image description here

like image 431
Victor Bocharsky Avatar asked Dec 24 '22 20:12

Victor Bocharsky


1 Answers

When you build the image you probably want to specify the image name with -t option.

docker build -t my/nginx .

To run a container use the run command

docker run --rm -ti my/nginx

You probably should add the following command to your Dockerfile

CMD ["nginx"]

Or with php5-fpm

CMD service php5-fpm start && nginx

UPDATE. You should run nginx as daemon off. Add the following to your Dockerfile after installing nginx.

RUN echo "daemon off;" >> /etc/nginx/nginx.conf

Update2.

-ti option in run allows you to check the log messages if any. Usually you should run a container in background using -d instead of -ti. You can attach to a running container using the attach command.

You may also check docker reference to see how to stop and remove a container and other commands.

like image 119
Oleg Pavliv Avatar answered Dec 29 '22 00:12

Oleg Pavliv